在Visual Studio中更改对齐线的间距 [英] Change spacing of snaplines in Visual Studio
问题描述
是否可以在Visual Studio中更改WinForms项目中控件之间放置的空间对齐线的数量?
Is it possible to change the amount of space snaplines put between controls in a WinForms project in Visual Studio?
例如,当我将一个文本框向上滑动到另一个文本框(一个在另一个之上)时,控件之间有6像素的间距.我希望它们彼此对齐时,它们之间应有5像素的间距.
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 for all of the answers. I thought it might be helpful to summarize the approaches:
选项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.
选项2
将布局模式"设置为SnapToGrid,然后通过默认网格单元大小"选择间距.感谢 Joe Caffeine和Marc Stober的答案
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.
补充方法1
Hold the ALT key when dragging controls to avoid using snapping altogether as Vigness.N suggested.
补充方法2
使用箭头键以像素为增量移动控件.
Use arrow keys to move controls in pixel increments.
补充方法3
Johannes Frank也建议添加占位符控件辅助初始对齐线.
Johannes Frank also suggests adding placeholder controls to assist with initial snaplines.
推荐答案
请注意,对齐线用于间距(蓝线)和对齐(粉红色线)
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.
在此处进行了讨论
编辑:在特殊情况下,当Form是父容器并且Form的填充为0,0,0,0时.
There is a special case when the Form is the parent container and the Form's padding is 0,0,0,0.
注意
如果窗体的Padding属性设置为0,0,0,0,则Windows窗体设计器将为窗体提供9、9、9、9的阴影遮蔽值.要覆盖此行为,请分配一个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.
这篇关于在Visual Studio中更改对齐线的间距的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!