5

I have a windows application that run in full screen and there are some panels inside my form which I want they stretch in width, I mean how i can add width=100% to these panel?

As you see in the below image, right panel is my inner one(container panel) that should stretch, it contains many items: 2 panels, toolstrip and a grid. I just set the Doc="Fill" and Anchor="top; right; left; bottom" to it but nothing changed.

enter image description here

Matt Stone
  • 291
  • 2
  • 4
  • 15

3 Answers3

11

To make the panel stretch to the whole of the form change the Anchor property of the panel control and set it to all four of them. Resize the control to stretch to the whole of the form.

panel1.Anchor = AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Bottom | AnchorStyles.Left;

Secondly for making a form fullscreen:

this.WindowState = FormWindowState.Maximized;
this.FormBorderStyle = FormBorderStyle.None;
M. Ahmad Zafar
  • 4,881
  • 4
  • 32
  • 44
4

In Windows Forms there are two ways of making controls size with the form: The Dock and Anchor properties:

enter image description here enter image description here

Docking provides you with a way of having controls at the edges of the form and a center control. Anchor allows you to state that a control should always have the same distance to a given set of edges. If you enable both the left and the right edge, then it will resize in width as the form resizes.

Joey
  • 344,408
  • 85
  • 689
  • 683
0

Anchors have caused me plenty of headaches. In WinForms, I prefer using the TableLayoutPanel for fluid layouts.

Just set the Dock of your TableLayoutPanel to Fill and you can specify your rows and columns, with absolute or relative sizes. Then just add your controls to the correct cell of your table and set their Dock to Fill.

Coming from WPF, this is similar to using a Grid and specifying your row and column definitions. You can also put TableLayoutPanels inside other TableLayoutPanels.

NielW
  • 3,626
  • 1
  • 30
  • 38