Embedded form and Anchor property

G

Guest

The following situation:
Panel control with Dock=Fill, inside a panel an embedded form with controls
in it.
The code embedding the form into the panel is this:
pnl.Controls.Add(form1);
Everything is working perfect, except the Anchor property of controls on the
embedded form is not working. The form has a grid that should be anchored to
all four sides, however, because the form is embedded into the panel, this
whole design is not working.
Am I missing anything? Any workaround?
Thank you in advance.
Cezar
 
G

Guest

Yes, I figured it out:
I need to call:
form.Anchor = ((AnchorStyles)((AnchorStyles.Bottom | AnchorStyles.Left |
AnchorStyles.Top | AnchorStyles.Right)));

The trouble was that the Anchor property was not available to the form in
the design time, and this is why I didn't know how to accomplish this.
However, at run time the property is perfectly available, so it's fine now..
 
H

Herfried K. Wagner [MVP]

Cezar said:
Panel control with Dock=Fill, inside a panel an embedded form with
controls
in it.
The code embedding the form into the panel is this:
pnl.Controls.Add(form1);
Everything is working perfect, except the Anchor property of controls on
the
embedded form is not working. The form has a grid that should be anchored
to
all four sides, however, because the form is embedded into the panel, this
whole design is not working.

Depending on the situation using a usercontrol instead of the embedded form
might be more appropriate.
 

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