在 C# 运行时以编程方式添加标签时,标签的可见性在“this.Controls.Add(whatever)”之后更改为 false,这不是真的。知道如何解决这个问题吗?
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Label label = new Label();
label.Location = new Point(15, 15);
label.Text = "Test";
label.AutoSize = true;
MessageBox.Show(Convert.ToString(label.Visible));
this.Controls.Add(label);
MessageBox.Show(Convert.ToString(label.Visible));
}
}
第一个MessageBox显示“true”,第二个MessageBox显示“false”
最佳答案
您正在将标签添加到尚未显示的表单中,因此当然,由于整个表单不可见,因此该表单上的标签也不可见。
显示表单时,标签将变为可见。
关于c# - this.Controls.Add() visibility = false,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25771452/