我想在用户选择他想要的颜色时更改标签的边框颜色。我知道标签的绘制事件可以更改边框颜色。我只想要这段代码:
private void label1_Paint(object sender, PaintEventArgs e)
{
ControlPaint.DrawBorder(e.Graphics, label1.DisplayRectangle, Color.Blue, ButtonBorderStyle.Solid);
}
要处理:
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if (comboBox1.SelectedIndex == 0)
{
//apply red color
}
}
要应用的组合框的选定索引(用户所需的颜色)。我只是不知道该怎么做。
Color selectedColor;
private void label1_Paint(object sender, PaintEventArgs e)
{
base.OnPaint(e);
ControlPaint.DrawBorder(e.Graphics, label1.DisplayRectangle, selectedColor, ButtonBorderStyle.Solid);
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if (comboBox1.SelectedIndex == 0)
{
selectedColor = Color.Red;
}
if (comboBox1.SelectedIndex == 1)
{
selectColor = Color.Blue;
}
label1.Invalidate();
label1.Update();
}