【问题标题】:Changing button color by clicking another button during runtime in visual basic?通过在 Visual Basic 运行时单击另一个按钮来更改按钮颜色?
【发布时间】:2019-12-18 07:44:33
【问题描述】:

我在按钮单击中创建了一个新按钮对象。现在想在被另一个按钮单击后更改按钮的颜色。

我创建了一个名为“btnBlank”的按钮对象,类似地给它一个名称为“btnBlank”,设置一个特定的位置点,给它一个大小,然后想给按钮一个颜色。但找不到方法。

        private void button17_Click(object sender, EventArgs e)
        {
              //  **** create a blank button(by btn object) ****
              Button btnBlank = new Button();      
              btnBlank.Name = "btnBlank";         
              btnBlank.Location = new System.Drawing.Point(50,50);     
              btnBlank.Size = new System.Drawing.Size(70,30);         
              //Color redColor = Color.FromArgb(255, 0, 0);
              btnBlank.BackColor = new System.Drawing.Color(redColor);    // here's the problem

              panel2.Controls.Add(btnBlank);
        }

【问题讨论】:

    标签: c# vba winforms runtime


    【解决方案1】:

    struct Color 已经将一些预定义的颜色初始化为静态成员。 只需这样做:

    btnBlank.BackColor = Color.Red
    

    更多info about Color.

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-12-25
      • 1970-01-01
      • 2015-02-23
      • 2016-03-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-07
      相关资源
      最近更新 更多