对齐文本框和标签文本 [英] Align TextBox and Label text

查看:76
本文介绍了对齐文本框和标签文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在设计UI时,发现自己很头疼:如何对齐并排排列的TextBox文本和标签文本.

I'm designing a UI, and I found myself itching my head : how can I align a TextBox text and a label text, which are side by side.

在设计模式下,这很容易,您可以用鼠标移动一个鼠标,然后出现一条紫色线,瞧!对齐方式很好,但是我的代码是生成的,所以如何对齐它们的内容?

In design mode, it's easy, you move one with your mouse, a purple line appears and voila ! the alignment is good, but mine are code generated, so how can i align their contents ?

谢谢!

编辑:布局是我不能使用的东西(我没有制定规则,老板是..)

Edit : Layout is something I can't use (I don't make the rules, my boss do..)

推荐答案

我喜欢为此目的使用FlowLayoutPanel(而不是TableLayoutPanel),因为您不需要摆弄列. 记住,以删除每个控件上的顶部和底部锚,以使其垂直居中,并设置FlowLayoutControl.AutoSize = true和AutoSizeMode = GrowAndShrink.

I like to use the FlowLayoutPanel (instead of the TableLayoutPanel) for this purpose because you don't need to fiddle with columns. Remember to remove both the Top and the Bottom anchors on every control to make them vertically centered, and set FlowLayoutControl.AutoSize = true and AutoSizeMode = GrowAndShrink.

编辑:关于布局是我不能使用的东西"的限制:因此,您想在运行时以编程方式访问紫色文本基线对齐线位置吗?这是可能的,但是它不可能比布局更快,因为只有控件的 designer 知道它在哪里,所以您将需要为此所需的所有控件创建设计器.

Edit: regarding your restriction that "Layout is something I can't use": so you want instead to access the purple text baseline snapline position programmatically, at runtime? This is possible, but it's unlikely to be faster than layouts because only the designer for the control knows where it is, so you will have to create designers for all controls you need this for.

此问题具有一些可用作起点的代码,但是正如我说的那样,考虑到性能限制,这可能也不是正确的方法.

This question has some code that can be used as a starting point, but as I said, it's probably not the right approach either given the performance constraints.

这篇关于对齐文本框和标签文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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