Finding control's Parent at Design Time

G

Guest

I have created a CustomControl that inherits from Textbox
When i drag and drop my custom control on to a UserControl/ form i want to
read the UserControl's property / form's property at Design Time
Ex : When i drag and Drop my Custom Control, i want the constructor of my
control to read my parent usercontrol's name property or any other property
and do some operation based on it

I already tried this.Parent but it returns a null value and throws an error.
Anyhelp with this would be of great use to me

Thanks,
Suraj Guptha
 
C

Chris Dunaway

Suraj said:
I have created a CustomControl that inherits from Textbox
When i drag and drop my custom control on to a UserControl/ form i want to
read the UserControl's property / form's property at Design Time
Ex : When i drag and Drop my Custom Control, i want the constructor of my
control to read my parent usercontrol's name property or any other property
and do some operation based on it

I already tried this.Parent but it returns a null value and throws an error.
Anyhelp with this would be of great use to me

I'm not sure if there is a way to do what you want, but you might try
not accessing the Parent in the constructor. It's possible that at the
time your constructor is called, your custom control has not been added
to the parent's controls collection.

If your custom control inherits from Control, you might try the
TopLevelControl property.

Chris
 
G

Guest

Hi Chris,
Let me explain exactly what i am trying to achieve. I have a
UserControl which has a colour property. If i set the usercontrol's color
property to green and if i drag drop my custom control into this usercontrol,
i want the customcontrol to have the same color as that of the
parentusercontrol.

Can you kindly let me know how to achieve this?
Thanks for your time.
Suraj Guptha
 
S

Stuart Carnie

Capture the HandleCreated and particularly the ParentChanged events of the control - you will be notified accordingly, when the
parent is set.

Cheers,

Stu
 

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