hWnd on Controls's parent

T

Tamir Khason

I need to fetch hWnd IntPtr of the form, which hold user control from inside
the user control. How to do this.
this.Handle returns wrong results.

Another question form the same field:
I want to use ONE and ONLY ONE Interoped ActiveX on my control. So in the
control I make static axControl wich get hWnd of the windows to show itself.
I override all disposes (to keep the instance) and make dispose on main
application, BUT when openning new instance of the same Windows which holds
my control (with static ActiveX in it) the ActiveX disappears from the
previouse window. In debugger I can see that while oppening second window it
reuse the static ActiveX from previouse window and, of couse, ActiveX
support to be runned from different iunstances at the same time (checked in
C++ project - there it works fine) What is the problem? Maybe doing
something wrong ...
One more problem with the same thing. When closing ALL instances of the
forms (holds controls with AX) I get an error "Cannot access a disposed
object", when all disposes are overrided.

Please advice
 
N

Nicholas Paldino [.NET/C# MVP]

Tamir,

You should not be doing this. What happens when you use a static
instance is that you are reassigning the handle of the window to different
parents, which is causing it to not work. Windows are meant to have one
parent, and what you are trying to do is not supported.

If you want to get the host of the control, then you can call the
FindForm method on the control, and it will get the form that this control
is hosted on. Once you have that, you can get its handle through the Handle
property.

Hope this helps.
 

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