Form.Handle inside a Component?

  • Thread starter Thread starter Ignacio X. Domínguez
  • Start date Start date
I

Ignacio X. Domínguez

Hi. I have created a component (System.ComponentModel.Component) that I
place on a form. Is there a way of obtaining the Form.Handle of the form
where I have placed my component?

Thank you
 
this.Handle is valid while coding the form, but I need to get while coding
the Component and there is no Handle member of a class derived from
Component.
 
Hi Ignacio,
this.Handle is valid while coding the form, but I need to get while coding
the Component and there is no Handle member of a class derived from
Component.

You can query the the static Form.ActiveForm member, but
take care: it's null when your app is not the active app,
ie. while switching with Alt-TAB, minimizing, etc.

The other way: what's the Container of the component? It's
the form, isn't it?

bye
Rob
 
Yes, I have the container, but I can't marshall it as a form. Maybe I'm
doing it wrong:

(System.Windows.Forms.Form)base.Container
 
Ignacio said:
Yes, I have the container, but I can't marshall it as a form. Maybe I'm
doing it wrong:

(System.Windows.Forms.Form)base.Container

This isn't calling "marshal". That's casting:

Form f = Container as Form;
if (f != null) {
// you have a form
}
 
Back
Top