垂直对齐 TableLayoutPanel 中的控件

发布于 2024-09-18 05:47:54 字数 130 浏览 10 评论 0原文

有没有办法让 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

山色无中 2024-09-25 05:47:54

选择表格布局面板中的所有控件。在属性选项卡中,确保锚点设置为“左”。我认为它默认为“顶部,左侧”。
希望这能把事情搞清楚。

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.

眼角的笑意。 2024-09-25 05:47:54

几天前我在研究它。我按照要求得到了一切。
试试这个:

对于标签

  • 从Tablelayoutpanel中分离标签
  • 将dockstyle设置为顶部
  • 设置锚点无
  • TextAlign = MiddleLeft
  • 然后将其放置在表格布局列中
  • 确保行样式高度匹配如果您有标签背景色,则标签高度。

对于文本框

  • 从Tablelayoutpanel中分离文本框
  • 将dockstyle设置为none
  • 将锚点设置为none
  • TextAlign = MiddleLeft(或根据需要)
  • 然后将其放置在表格布局列中

I worked on it a few days back. I got everything as required.
Try this:

For Labels

  • Detach label from Tablelayoutpanel
  • Set dockstyle to top
  • Set anchor points none
  • TextAlign = MiddleLeft
  • Then just place it in the table layout column
  • Make sure the row style height matches label height if you have a label backcolor.

For Textboxes

  • Detach textboxes from Tablelayoutpanel
  • Set dockstyle to none
  • Set anchor points none
  • TextAlign = MiddleLeft (or as required)
  • Then just place it in the table layout column
如梦初醒的夏天 2024-09-25 05:47:54

您可以设置以下属性:

对于标签
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............

情徒 2024-09-25 05:47:54

我建议保持锚点不变,只为太高的控件添加顶部边距。当我添加标签时,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.

弥枳 2024-09-25 05:47:54

哦,您的意思是标签的文本基线与其他控件不同?
如果是这样,请尝试删除垂直锚点。你也可以玩边距。

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.

清晰传感 2024-09-25 05:47:54

我通常做的是将它们放入容器(例如面板)中,并将它们相对于该容器固定。
添加容器的优点是还可以减少 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.

天生の放荡 2024-09-25 05:47:54

您可以尝试使用修改后的文本框而不是标签: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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文