简体   繁体   English

如何解决标签的某些文本已被文本框隐藏的问题?

[英]How to fix this issue that some of the text of the label has been hidden by textbox?

在此处输入图片说明

The text of the label is written programmatically: 标签的文本以编程方式编写:

public Form1()
{
    InitializeComponent();
    label.Text = data from database;
}

You could set the Dock property each of the controls. 您可以为每个控件设置Dock属性。 Depending on your layout you can set each of them to DockStyle.Left and set the AutoSize property of the label to true. 根据您的布局,可以将它们分别DockStyle.LeftDockStyle.Left并将标签的AutoSize属性设置为true。 If you can't dock them as is, you can put them inside of a panel and dock inside of the panel. 如果您不能按原样停靠,则可以将它们放置在面板内,然后停靠在面板内。 When inside of the panel you can also take advantage of the Fill style of docking (which would also work outside of the panel, but depending on the rest of the controls in your layout it could screw them up. Inside of a panel you can set the label to DockStyle.Left and the TextBox to DockStyle.Fill (to take up the rest of the space) 在面板内部时,您还可以利用“停靠”的“填充”样式(也可以在面板外部使用,但是根据布局中其余控件的不同,它可能会将它们拧紧。在面板内部,您可以设置该标签DockStyle.Left和文本框DockStyle.Fill (占用空间的其余部分)

Set the label's MaximumSize.Width property so it cannot overlap the TextBox. 设置标签的MaximumSize.Width属性,使其不能与TextBox重叠。 If you don't have enough space vertically then also set the MaximumSize.Height property. 如果您在垂直方向上没有足够的空间,则还可以设置MaximumSize.Height属性。 You then should also consider setting AutoEllipsis to True so that it is obvious to the user that the text got truncated, a tooltip shows the full text. 然后,您还应该考虑将AutoEllipsis设置为True,这样对于用户来说,很明显文本被截断了,工具提示显示了全文。

An easy way to determine the proper values for MaximumSize is to temporarily turn AutoSize off. 确定MaximumSize正确值的一种简单方法是暂时关闭AutoSize。 Adjust the label size to the maximum size that doesn't overlap anything. 将标签尺寸调整为不重叠的最大尺寸。 Copy/paste the Size into AutoSize. 将尺寸复制/粘贴到AutoSize中。 Or leave it off. 还是别管它了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM