1

Can I resize components automatically when a form is resized? Not in code, but in the form designer.

I'm trying to create an 'abstract form' for me and the others developers use it as an 'inherited form'.

I am drawing the form with four panels: top and bottom, and both sides. And I need when the form is resized, the panels will be resized too.

gunr2171
  • 16,104
  • 25
  • 61
  • 88
Jéf Bueno
  • 425
  • 1
  • 5
  • 23
  • 1
    Yes, either by using the `Anchor` property or in c# code. What do you mean by "Not in execution, but in the VS"? – gunr2171 Nov 20 '14 at 18:13

2 Answers2

2

You can set the Anchor property of components. the Anchor property defines how a control is automatically resized as its parent control is resized. Anchoring a control to its parent control ensures that the anchored edges remain in the same position relative to the edges of the parent control when the parent control is resized.

You can anchor a control to one or more edges of its container. For example, if you have a Form with a Button whose Anchor property value is set to Top and Bottom, the Button is stretched to maintain the anchored distance to the top and bottom edges of the Form as the Height of the Form is increased.

To do that programmatically use the code like

control1.Anchor = AnchorStyles.Bottom | AnchorStyles.Top | AnchorStyles.Left;

http://msdn.microsoft.com/en-us/library/system.windows.forms.control.anchor%28v=vs.110%29.aspx

Ahmad
  • 8,811
  • 11
  • 76
  • 141
0

Try using myControl.Dock = DockStyle.Fill;

isxaker
  • 8,446
  • 12
  • 60
  • 87