Accessing a form from a component

G

Guest

Okay I'm stumped on this one. I want to develop a component (not a control or usercontrol as it needs no interface) that does interact with the form on which it is dropped. How do I get access to the Form in which the component is dropped? The MainMenu component seems to be able to do this but I cannot figure out how as component does not inherit the convinient Parent attribute of the control family..... I'm sure I'm just being a bit thick but any help would be appreciated.
 
S

Stoitcho Goutsev \(100\) [C# MVP]

Trevor,

There is no way to find this. You can only find the container of the
component. That's all.
In the case with MainMenu. the form is the one that makes this happen.
If you look at form's InitializeComponent method in the section where the
form initializes itself you'll find the line

this.Menu = this.mainMenu1;

That's it. The form sets a reference to itself in the Menu property.

--
B\rgds
100 [C# MVP]

Trevor said:
Okay I'm stumped on this one. I want to develop a component (not a
control or usercontrol as it needs no interface) that does interact with the
form on which it is dropped. How do I get access to the Form in which the
component is dropped? The MainMenu component seems to be able to do this
but I cannot figure out how as component does not inherit the convinient
Parent attribute of the control family..... I'm sure I'm just being a bit
thick but any help would be appreciated.
 
G

Guest

Ta for that, I guess I will have to take that route too.. I just hoped there was a neater option

----- Stoitcho Goutsev (100) [C# MVP] wrote: ----

Trevor

There is no way to find this. You can only find the container of th
component. That's all
In the case with MainMenu. the form is the one that makes this happen
If you look at form's InitializeComponent method in the section where th
form initializes itself you'll find the lin

this.Menu = this.mainMenu1

That's it. The form sets a reference to itself in the Menu property

--
B\rgd
100 [C# MVP

Trevor said:
Okay I'm stumped on this one. I want to develop a component (not
control or usercontrol as it needs no interface) that does interact with th
form on which it is dropped. How do I get access to the Form in which th
component is dropped? The MainMenu component seems to be able to do thi
but I cannot figure out how as component does not inherit the convinien
Parent attribute of the control family..... I'm sure I'm just being a bi
thick but any help would be appreciated
 

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