C# 如何获得刷子颜色?
FormDesign中有按钮。如果单击第一个按钮C# 如何获得刷子颜色?,c#,winforms,colors,drawing,brush,C#,Winforms,Colors,Drawing,Brush,FormDesign中有按钮。如果单击第一个按钮 brush = Brushes.Red; 每个按钮都有这样的代码。我想为那一刻染上颜色。我怎样才能得到它 Color c = (color of brush); 这边 编辑:我想在列表中保留颜色数据。您可以使用控件获取颜色。BackColor和控件。ForeColor是各种类型画笔的父类;只有具有颜色属性的 因此,您需要强制转换到SolidBrush: 要么: Brush b1 = Brushes.Red; Color c1
brush = Brushes.Red;
每个按钮都有这样的代码。我想为那一刻染上颜色。我怎样才能得到它
Color c = (color of brush);
这边
编辑:我想在列表中保留颜色数据。您可以使用
控件获取颜色。BackColor
和控件。ForeColor
是各种类型画笔的父类;只有具有颜色属性的
因此,您需要强制转换到SolidBrush
:
要么:
Brush b1 = Brushes.Red;
Color c1 = ((SolidBrush)b1).Color;
或
下面的代码演示了更改按钮颜色的按钮单击,按钮颜色存储在字符串中
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); }
}
private void按钮1\u单击(对象发送者,事件参数e)
{
刷子刷子1=刷子。红色;
button1.BackColor=((SolidBrush)brush1).颜色;
字符串getColor1;
getColor1=button1.BackColor.ToString();
MessageBox.Show($“按钮颜色1”+getColor1);
//类似地,将其他按钮颜色存储在字符串中
字符串getColor2=“橙色”字符串getColor3=“蓝色”;
//将这些字符串值存储在列表中
列表颜色=新列表();
添加(getColor1);
添加(getColor2);
添加(getColor3);
foreach(颜色中的字符串颜色){MessageBox.Show(颜色);}
}
画笔。颜色
?不,我写“画笔”。但是“颜色”不出现。你用这个画笔来改变按钮的颜色吗?画笔来自哪里??示例:SolidBrush b=(SolidBrush)brush.Red;颜色c=b。颜色代码>在公共分部类Form1中,Brush Brush=Brush.red谢谢。我想在列表中保留颜色。我该怎么做?我试着把它作为字符串列表保存。这样染颜色没关系。但我不能用它。因为我将用列表中的颜色绘制。我怎么做?我想和他们一起画画。e、 Graphics.FillPolygon((使用颜色[0]),点)如何将该字符串转换为颜色并与画笔一起使用?这是一个完全不同的问题,您可以将问题与要求一起发布吗?给你
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); }
}