Tutorial :WinForm designer and right snapline for controls in container when resizing it


Using Visual Studio 2008 WinForm designer, I have a container (form, panel, groupbox, whatever) and some controls in it.

The container is set to not automatically resize or dock in any way. When placing a control in the container I can use the snaplines to help in positioning the control.

However, the snaplines does not appear when I resize the container to the edge of the contained controls...

Is there a simple way to have the designer show me the snaplines of the contained controls when resizing the container?


The designer will only show the snap lines when moving a child control within a container. You can demonstrate it by moving a GroupBox around a Form and see that it shows snap lines when the GroupBox gets close to the edge of the Form, but if you were to resize the Form you won't see the snap lines appear.

If you're just looking to get all of the controls to line up in a uniform fashion, I'd suggest switching to SnapToGrid mode and using the grid lines to align your controls. You can set the SnapToGrid mode by going to Tools->Options->Windows Forms Designer->LayoutMode. Open your designer and you should see the grid appear, after that you can line your controls up with the grid.


After setting the layout of the form, you can also set anchoring property to all child controls appropriately, to right and bottom (or top and left), depending on the resizing you are making. Anchor property will hold child controls to same distance from the edges of the container (parent control).


In the WinForms designer, there is no support for snaplines when resizing the container control. The best way to work around this issue is to first size the container to the size you would like to use and then add controls. Optionally, you can change the Margin property of the container so that when moving controls inside the container, they will snap to the margin of the container, keeping it uniform.



  • container.AutoSize = true
  • container.AutoSizeMode = GrowAndShrink
  • container.Padding.All = 5

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »