Getting MDI Child Form from its handle

  • Thread starter Thread starter Marcolino
  • Start date Start date
M

Marcolino

Hi all,
I have an MDI container and some child.
I need to retrive Form Object from its handle, but it seems that for
MDI child the following code i'm using is not working and will return
me always nothing:

i variable is an integer containing the handle of a for I want to get,
and frmPostIt is my child

Dim frm As frmPostIt
frm = System.Windows.Forms.Form.FromHandle(i)

with this code applied to an MDI child will always return frm=Nothing,
but works with normal form.
Do you have any suggestion?

Many Thanks
 
Marcolino said:
Hi all,
I have an MDI container and some child.
I need to retrive Form Object from its handle, but it seems that for
MDI child the following code i'm using is not working and will
return me always nothing:

i variable is an integer containing the handle of a for I want to
get, and frmPostIt is my child

Dim frm As frmPostIt
frm = System.Windows.Forms.Form.FromHandle(i)

with this code applied to an MDI child will always return
frm=Nothing, but works with normal form.
Do you have any suggestion?

I'd
1. Enable Option Strict
2. declare i As Intptr
3. Use System.Windows.Forms.Control.FromHandle
4. Cast the return value to frmPosIt if you are sure that this will
_always_ be the type. (Out of interest: Why do you only have a handle,
not a Form reference? Where do you get the handle from?)

Does it work now? I've tried with an MDI child it and it did work.


Armin
 
I'd
1. Enable Option Strict
2. declare i As Intptr
3. Use System.Windows.Forms.Control.FromHandle
4. Cast the return value to frmPosIt if you are sure that this will
_always_ be the type. (Out of interest: Why do you only have a handle,
not a Form reference? Where do you get the handle from?)

Does it work now? I've tried with an MDI child it and it did work.

Armin

Hi Armin,
thanks for your suggestion.
Do you have an example on how do it?
I'm just in trouble with Enable Oprion Strict.

Thanks
 
Marcolino said:
Hi Armin,
thanks for your suggestion.
Do you have an example on how do it?
I'm just in trouble with Enable Oprion Strict.

With enabling it or with the consequences?

'Option Strict On' is the command on a per file basis. Add it as the
first line in the code file. For the whole project, you can change the
setting in the project's properties (on the 'compile' folder: Option
Strict = On)


Armin
 
Back
Top