我一直在努力让我的表单根据用户选择的选项立即更改背景颜色。他可以选择红色、绿色和蓝色。我试图使用 system.drawing.color 但我似乎无法让表单改变它的颜色。它应该使用代表。
我只是在学习无模式对话框。请帮忙...
到目前为止,这就是我所做的:
public partial class ChangeColors : Form
{
//Delegate the observer needs to notify if something changes
public delegate void ChangeColorEvent(Color nameColor);
// Name of the event which is tied to the delegate
public event ChangeColorEvent ChangeColor;
public enum color { Red, Green, Blue };
private color selectedColor;
public color SelectedColor
{
get
{
return selectedColor;
}
set
{
selectedColor = value;
}
}
public ChangeColors()
{
InitializeComponent();
selectedColor = color.Blue;
}
private void backColor_ColorChanged(Control control)
{
if (redRadioButton.Checked)
this.BackColor = System.Drawing.Color.Red;
else if (blueRadioButton.Checked)
this.BackColor = System.Drawing.Color.Blue;
else
this.BackColor = System.Drawing.Color.Green;
}
private void okButton_Click(object sender, EventArgs e)
{
this.Close();
}
}