如何获得画笔颜色?

时间:2018-05-05 18:43:15

标签: c# winforms colors drawing brush

FormDesign中有按钮。如果单击第一个按钮,

        brush = Brushes.Red;

每个按钮都有这样的代码。我想在那一刻得到刷子的颜色。我怎么能得到它;

Color c = (color of brush);
这样吗?

编辑:我想将颜色数据保存在列表中。

3 个答案:

答案 0 :(得分:0)

您可以使用i['Appointment Date']datetime获取颜色。

答案 1 :(得分:0)

Brush是各种类型画笔的父类;只有SolidBrush具有Color属性。

所以你需要施展到SolidBrush

要么:

Brush b1 = Brushes.Red;
Color c1 = ((SolidBrush)b1).Color;

SolidBrush b2 = (SolidBrush)Brushes.Red;
Color c2 = b2.Color;

答案 2 :(得分:0)

下面的代码说明了一个Button Click,它改变了Button的颜色,Button的颜色存储在 String

 private void button1_Click(object sender, EventArgs e)
      {
         Brush brush = new SolidBrush(Color.Red);
         button1.BackColor = ((SolidBrush)brush).Color;

         string getColor;
         getColor = button1.BackColor.ToString();
         MessageBox.Show($"Color of Button1  " + getColor);

      }

private void button1_Click(object sender, EventArgs e)
      {
         Brush brush1 = Brushes.Red;
     button1.BackColor = ((SolidBrush)brush1).Color;

     string getColor1;
     getColor1 = button1.BackColor.ToString();
     MessageBox.Show($"Color of Button1  " + getColor1);

     //Similarly store other button colors in a string
     string getColor2 = "Orange"; string getColor3 = "Blue"; 

     //Store these string value in a list 
     List<string> colors = new List<string>();
     colors.Add(getColor1);
     colors.Add(getColor2);
     colors.Add(getColor3);
     foreach (string color in colors) { MessageBox.Show(color); }
      }

enter image description here