【问题标题】:Button is not visible [duplicate]按钮不可见[重复]
【发布时间】:2016-10-01 05:25:50
【问题描述】:

我想在表单的开头使用 C# 代码创建一个按钮,但它没有显示在屏幕上。我的代码就在下面。

private void Form1_Load(object sender, EventArgs e) 
{
    Button b = new Button();
    b.Size = new Size(btnWidth, btnHeight);
    b.Location = new Point(30 , 30 );
    b.Visible = true;
    b.Text = "X";
}

【问题讨论】:

    标签: c# winforms


    【解决方案1】:

    因为您没有将Button 添加到您的FormControlCollection。您需要 Control.ControlCollection.Add 方法。所以在你的代码末尾添加这一行:

    Controls.Add(b);
    

    【讨论】:

      猜你喜欢
      • 2011-10-21
      • 2021-10-10
      • 2013-09-09
      • 1970-01-01
      • 2021-02-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-15
      相关资源
      最近更新 更多