我有像这样的基本表单类,它继承自类
public partial class BaseForm : Form
{
protected override void OnLoad(EventArgs e)
{
Color colBackColor =Properties.Settings.Default.FormsBackgroundColor;
BackColor = colBackColor;
}
}
和MainForm类一样,它继承了BaseForm类。
public partial class MainForm : BaseForm
{
private void button1_Click_1(object sender, EventArgs e)
{
ColorDialog colorDlg = new ColorDialog();
if (colorDlg.ShowDialog() == DialogResult.OK)
{
Properties.Settings.Default.FormsBackgroundColor= colorDlg.Color;
Properties.Settings.Default.Save();
this.Refresh();
this.Invalidate();
}
}
}
当我单击 MainForm 上的 button1 并从颜色对话框中选择颜色时。 MainForm 的背景颜色不变。我做错了什么?
顺便说一句,当我重新运行应用程序时,颜色会发生变化。
The OnLoad
该事件仅在表单加载时触发,单击按钮时不会触发。所以你需要改变表单的BackColorbutton1_Click_1
also.
if (colorDlg.ShowDialog() == DialogResult.OK)
{
Properties.Settings.Default.FormsBackgroundColor= colorDlg.Color;
Properties.Settings.Default.Save();
this.BackColor = colorDlg.Color;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)