在 Windows 窗体设计器中将控件与窗体的中心对齐 [英] Align controls to the center of a form in Windows Forms designer

查看:50
本文介绍了在 Windows 窗体设计器中将控件与窗体的中心对齐的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这让我很不爽:我怎样才能让 Windows 窗体设计器为我正在处理的窗体的水平和垂直中心提供像素捕捉?

This is something that's been driving me up the wall: how can I get the Windows Forms designer to provide pixel snapping for the horizontal and vertical centers of the form I'm working on?

推荐答案

Visual Studio 提供了许多工具来帮助对齐表单中的控件组和调整控件组的大小.使用布局工具栏访问这些功能.要显示布局工具栏,请右键单击标准 Visual Studio 工具栏的任何部分,然后从下拉菜单中选择布局".生成的工具栏将显示如下:

Visual Studio provides a number of tools to assist in aligning groups and sizing groups of controls in a form. These features are accessed using the layout toolbar. To display the layout toolbar right click on any part of the standard Visual Studio Toolbar and select Layout from the drop down menu. The resulting toolbar will appear as follows:

Visual Studio 布局工具栏

The Visual Studio Layout Toolbar

选择一组组件,点击工具栏中的各个按钮,查看效果.例如,所有控件都可以左对齐或右对齐并调整为相同的大小、宽度或高度.也可以将控件等距,然后增加或减少用于分隔控件的间距.也可以将控件放在另一个顶部并更改哪个控件显示在堆栈顶部(这也可以在 Visual Basic 代码中使用相应控件的BringToFront() 和SendToBack() 方法完成).

Select a group of components and click on the various buttons in the toolbar to see the effect. For example, all the controls can be left or right aligned and resized to the same size, width or height. It is also possible to equally space the controls, and then increase or decrease the spacing used to separate the controls. It is also possible place controls on top of one another and change which control appears on top of the stack (this can also be done in Visual Basic code using the BringToFront() and SendToBack() methods of the respective controls).

总的来说,控件的选择允许从表单中的一组控件实现几乎任何统一的布局.

All together, the selection of controls allows just about any uniform layout to be achieved from a group of controls in a form.

http://www.techotopia.com/index.php/Designing_Forms_in_Visual_Studio

右端的第 5 个和第 6 个图标将为您解决问题:

5th and 6th icon from the right end will do the trick for you:

  • 水平居中
  • 垂直居中

不是很自动,但仍然有效.

Not quite automatic, but still works.

这篇关于在 Windows 窗体设计器中将控件与窗体的中心对齐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆