Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change spacing of snaplines in Visual Studio

Is it possible to change the amount of space snaplines put between controls in a WinForms project in Visual Studio?

For example, when I slide a textbox up to another textbox (one above the other), there's 6 pixels of space between the controls. I'd like there to be 5 pixels of space between them when they snap to each other.

Thanks.


EDIT:

Thanks for all of the answers. I thought it might be helpful to summarize the approaches:

Option 1

Set the Layout Mode to SnapLines (default) under Tools > Options > Windows Forms Designer > General and follow Igby Largeman's guidance in the accepted answer.

Option 2

Set the Layout Mode to SnapToGrid and choose the spacing via Default Grid Cell Size. Thanks to Joe Caffeine and Marc Stober for this answer.

Supplemental approach 1

Hold the ALT key when dragging controls to avoid using snapping altogether as Vigness.N suggested.

Supplemental approach 2

Use arrow keys to move controls in pixel increments.

Supplemental approach 3

Johannes Frank also suggests adding placeholder controls to assist with initial snaplines.

like image 636
ifugu Avatar asked Sep 04 '09 00:09

ifugu


People also ask

How do I create a grid in Visual Studio?

In Visual Studio, from the Tools menu, select Options. In the left pane of the Options dialog box, click Windows Forms Designer. In the right pane, under the Layout Settings heading, you can set the default grid settings for all the new forms you create.

Which window is placed in the form of grid used to design a form?

Answer. Form Layout window is a simple visual basic design tool whose purpose is to give the user a thumbnail view of the current form. ...


3 Answers

There are no snaplines that help you set the spacing between controls, they assist in aligning control edges and text. Instead, the designer pays attention to the Margin property of the control. The default for a Button is (3, 3, 3, 3), it will snap in place creating a 3 pixel gap from the adjacent control.

Best to try it yourself. Drop a label and a button, change the button's Margin to (3, 10, 3, 3) and move the Button below label up and down. You'll see it now snaps in place creating a 10 pixel gap.

like image 180
Hans Passant Avatar answered Nov 08 '22 12:11

Hans Passant


Note that snaplines are used both for spacing (blue lines) and for alignment (pink lines).

Yes, you can control the amount of space the snaplines suggest, but you do this by altering the Margin and Padding properties of the controls.

If you slide one control toward another, the length of the snapline is the sum of the Margin of the two controls.

If you slide a control toward the border of its containing control, the length of the snapline is the sum of the Margin of the control and the Padding of the containing control.

This is discussed here.

Edit: There is a special case when the Form is the parent container and the Form's padding is 0,0,0,0.

Note
If the form's Padding property is set to 0,0,0,0, the Windows Forms Designer gives the form a shadowed Padding value of 9,9,9,9. To override this behavior, assign a value other than 0,0,0,0.

like image 27
Igby Largeman Avatar answered Nov 08 '22 14:11

Igby Largeman


There is a setting to control the grid spacing under tools -> options -> Windows Forms Designer.

like image 1
Joe Caffeine Avatar answered Nov 08 '22 14:11

Joe Caffeine