C# 使用组合框更改笔刷颜色
我需要C# 使用组合框更改笔刷颜色,c#,combobox,C#,Combobox,我需要组合框索引来更改画笔/笔的颜色,当它被选中时,我知道这应该是一个简单的修复,但我似乎无法获得它 public partial class Form1 : Form { private bool penDown = false; private int radius = 5; private SolidBrush brush = new SolidBrush(Color.IndianRed); private Color[] colors = { Color
组合框
索引来更改画笔/笔的颜色,当它被选中时,我知道这应该是一个简单的修复,但我似乎无法获得它
public partial class Form1 : Form
{
private bool penDown = false;
private int radius = 5;
private SolidBrush brush = new SolidBrush(Color.IndianRed);
private Color[] colors = { Color.IndianRed, Color.Blue, Color.Green, Color.Yellow, Color.Purple};
public Form1()
{
InitializeComponent();
}
private void btnClr_Click(object sender, EventArgs e)
{
Graphics g = panel1.CreateGraphics();
g.Clear(panel1.BackColor);
g.DrawImage(panel1.BackgroundImage, panel1.ClientRectangle, 0, 0, panel1.BackgroundImage.Width,
panel1.BackgroundImage.Height, GraphicsUnit.Pixel);
g.Dispose();
}
private void btnQuit_Click(object sender, EventArgs e)
{
base.Close();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void panel1_MouseMove(object sender, MouseEventArgs e)
{
if (!penDown)
{
return;
}
Graphics g = panel1.CreateGraphics();
g.FillEllipse(brush, new Rectangle(e.X - radius, e.Y - radius, 2 * radius, 2 * radius));
g.Dispose();
}
private void panel1_MouseDown(object sender, MouseEventArgs e)
{
penDown = true;
}
private void panel1_MouseUp(object sender, MouseEventArgs e)
{
penDown = false;
}
private void colorCB_SelectedIndexChanged(object sender, EventArgs e)
{
//int i = ((color
}
}
只需使用组合框
SelectedIndex
属性从colors
数组中检索颜色:
private void colorCB_SelectedIndexChanged(object sender, EventArgs e)
{
brush = new SolidBrush(colors[colorCB.SelectedIndex]);
}
brush=newsolidbrush(颜色[colorCB.SelectedIndex])代码>