Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
582 views
in Technique[技术] by (71.8m points)

winforms - 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...