Unless your control takes the parent as a parameter to the constructor,
there would be no way to know the parent.
When you create an instance of the control, it is not associated with
any other controls until you specifically add it to them.
You might want to create a method like this on your control:
public void AssignToParent(Control parent){
this.Parent = parent;
// do stuff that references the parents dimensions
}
Then you can do something like:
Panel mainPanel = new Panel();
....
MyControl x = new MyControl();
x.AssignToParent(mainPanel);
Jim Margarit wrote:
I'm trying to write my first windows control, subclassed from Panel.
In the constructor I try to use the parent property but it is undefined
(null). Is there any way to get to the parent in the constructor? I want
to know the dimensions of the parent container. Thanks
Jim Margarit