Visual Studio 2010 中的控制捕捉
我只是在这里挑剔,但也许有一个简单的解决方案可以节省我一些时间。
当我在设计器中绘制 Winforms GUI 时,控件会捕捉到某些点。我可以将一个控件的文本基线与另一个控件的文本基线对齐,我可以将一个控件的左侧和/或顶部与另一个控件对齐,等等。这一切都很棒。
同样很棒的是,这些控件可以与其他控件对齐,并与其边距间隔开。这意味着,如果我要制作一个垂直的文本框数组,那么我可以让它们在 GUI 中等距 - 它看起来不那么混乱。
然而,并不是所有的东西都能正确地捕捉,或者根本不能捕捉。假设我已经放入了文本框,现在我希望减小表单的宽度,以便文本框的边缘和表单的边缘之间没有空白。此外,我希望文本框边缘和表单边缘之间的距离左侧与右侧相同。如果我将窗体的右边缘向左拖动到文本框,它将不会对齐。我要么通过计算来计算出宽度应该是多少,要么通过杂耍行为来逐渐减小宽度,直到 TextBox 对齐到左侧和右侧。
我并不是说这个过程特别困难或耗时。只是如果折断的话,整个过程就会变得无比简单。
VS2010中有内置选项或者扩展吗?或者也许我一开始就做错了?
I'm sort-of just nit picking here, but maybe there's a simple solution which will save me some time.
When I'm drawing my Winforms GUI in the designer, controls snap to certain points. I can align the baseline of the text of one control to that of another, I can align the left and/or top of one control to another, etc. This is all great.
What's great too, is that the controls snap to other controls spaced with their margins. This means that if I'm making a vertical array of TextBoxes, then I can have them equidistant in my GUI - it looks less messy.
However not everything snaps correctly, or at all. Say I have put in my TextBoxes and now I wish to reduce the width of my form so that there is no white space between the edges of the TextBoxes and the edge of the form. Additionally, I want the distance between the edge of the TextBoxes and the edge of the Form to be the same on the left as it is on the right. If I drag the right edge of the form to the left, towards the TextBoxes it will not snap. I'm left with either calculations to work out what the width should be, or a juggling act to gradually reduce the width until the TextBox is snapping to both the left of the right.
I'm not saying this process is particularly difficult or time consuming. It's just that if it were to snap, the whole process would be infinitely easier.
Is there a built-in option in VS2010, or perhaps an extension? Or maybe I'm just doing it wrong in the first place?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当移动或调整任何内置控件的大小时,设计器中的对齐线可以完美地工作。它们唯一不起作用的时候是当您调整表单本身的大小时。
我同意这里也有对齐线会非常方便。我希望我知道一种方法来实现这一点。但不幸的是,我不相信有这样的人。
解决方法是通过数学方法计算正确的大小,或者猜测调整表单大小,然后通过拖动其中一个控件(并使用出现的对齐线)来检查您的工作。不幸的是,我经常经历你所描述的同样的“杂耍行为”。
The snap lines in the designer work perfectly when moving or resizing any of the built-in controls. The only time that they don't work is when you are resizing the form itself.
I agree that it would be extremely convenient to have snap lines here, as well. I wish I knew of a way to enable this. But unfortunately, I don't believe that there is one.
The workarounds are either to calculate the proper size mathematically, or guess at resizing the form then check your work by dragging one of the controls (and using the snap lines that appear). I go through the same "juggling act" that you describe on an unfortunately regular basis.
每当需要定位控件以使其“捕捉”到表单边缘时,我通常首先将控件移动(或调整大小)到正确的大小,然后更改这些控件的控件“锚定”属性以锚定到相应的位置表单边缘(即使表单本身不允许调整大小)。
这样,每当我调整表单大小时,控件相对于该表单的位置保持不变,只需根据需要调整大小或移动控件(取决于所选的 Anchor 属性)。
我完全同意,在调整表单大小时将表单“捕捉”到控件的能力将非常有用,但通常可以通过这种方式使用锚属性来解决问题 - 当它不起作用时(例如当表单完全由一列文本框组成时,其高度是固定的),恐怕您需要求助于计算,但我发现我的大多数对话框都是可调整大小的。
Whenever a control needs to be positioned so that it "snaps" to a form edge I usually move (or resize) the controls to the correct size first, and then change the controls "Anchor" property of those controls to be anchored to the corresponding form edge (even if the form itself won't be allowed to resize).
That way whenever I resize the form, the controls position relative to that form remains the same, simply resizing or moving the control as required (depending on the Anchor property chosen).
I completely agree that the ability to "snap" the form to controls when resizing the form would be extremely useful, but its normally possible to work-around using the anchor property in this way - the times when its doesn't work (such as when a form consists entirely of a column of text-boxes is a fixed height), I'm afraid you need to resort to calculations, but I find that most of my dialogs are resizable.