垂直对齐 TableLayoutPanel 中的控件
有没有办法让 TableLayoutPanel 上的控件文本内容正确对齐?我在第 0 列中有标签,在第 1 列中有文本框(或有时是 ComboBox 或 NumericUpDown 控件),但标签中的文本在大多数行上通常是一个或两个像素(垂直)。
Is there any way to have textual content of controls on a TableLayoutPanel align themselves properly? I've got labels in column 0, and textboxes (or occasionally ComboBox or NumericUpDown controls) in column 1, but the text in the label is usually a pixel or two out (vertically) on most rows.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
选择表格布局面板中的所有控件。在属性选项卡中,确保锚点设置为“左”。我认为它默认为“顶部,左侧”。
希望这能把事情搞清楚。
Select all the controls in your table layout panel. In the properties tab ensure anchor set to 'left'. I think it defaults to 'top,left'.
Hope that sets things straight.
几天前我在研究它。我按照要求得到了一切。
试试这个:
对于标签
TextAlign = MiddleLeft
对于文本框
TextAlign = MiddleLeft
(或根据需要)I worked on it a few days back. I got everything as required.
Try this:
For Labels
TextAlign = MiddleLeft
For Textboxes
TextAlign = MiddleLeft
(or as required)您可以设置以下属性:
对于标签
1.
Autosize= false;
2.
TextAlign= MiddleLeft;
对于 Combobox、Textbox 等控件
,转到 View ->工具栏->布局
现在,您可以通过工具栏一次选择多个控件,轻松地对控件进行布局............
You can set following properties:
for Label
1.
Autosize= false;
2.
TextAlign= MiddleLeft;
for Controls like Combobox,Textbox
goto View -> Toolbars -> Layout
Now you can give layout of your controls very easily by the Toolbar by selecting Multiple Controls at a Time............
我建议保持锚点不变,只为太高的控件添加顶部边距。当我添加标签时,3、6、3、0 的边距对我来说是正常的。正如 Javed 所说,您可以通过单击控件来选择多个控件。让我恼火的是 ComboBox 比 Texbox 大 1 个像素。但对此无能为力。
I'd recommend leaving the anchors as they are and just adding a top margin to the controls that are too high. A margin of 3,6,3,0 is normal for me when I'm adding labels. As Javed said you can select multiple controls by control clicking. It irritates me that ComboBoxes are one pixel larger than Texboxes. Can't do much about that though.
哦,您的意思是标签的文本基线与其他控件不同?
如果是这样,请尝试删除垂直锚点。你也可以玩边距。
Oh, you mean that text baseline for label is different than for other controls?
If so, try to remove vertical anchors. You may play with margins as well.
我通常做的是将它们放入容器(例如面板)中,并将它们相对于该容器固定。
添加容器的优点是还可以减少 Win 处理程序的数量。在这种情况下,这并不重要,因为您已经有了 TablelayoutPanel,所以基本上对于所有控件,您只有一个处理程序。
What I usually do is put them in a container eg a panel and anchor them relatively to that.
The advantages of adding a container is you can also reduce the no of Win handlers. In that case that wouldn't matter , because you already have the TablelayoutPanel so basically for all the controls you only have a single handler.
您可以尝试使用修改后的文本框而不是标签:https://stackoverflow.com/a/75815030/2408668
该解决方案也适用于更高的 DPI。
You can try to use the modified TextBox instead of the Label: https://stackoverflow.com/a/75815030/2408668
This solution works also for the higher DPIs.