Getting MDI Child Form from its handle

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
 
A

Armin Zingler

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
 
M

Marcolino

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
 
A

Armin Zingler

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top