例如,当用户改变背景颜色时,Settings.settings文件被修改。它的工作原理。C#重新加载表单
但是,用户单击确定后,应用程序不会更改它的背景色。 只有当我再次关闭并构建应用程序时才有效。
如何在按钮单击时重新加载我的表单或用户控件? (试图与.REFRESH(),但它不工作)
private void refreshSettings()
{
this.BackColor = Properties.Settings.Default.bgdColor;
this.Font = Properties.Settings.Default.fontType;
this.ForeColor = Properties.Settings.Default.fontColor;
}
private void Settings_Load(object sender, EventArgs e)
{
refreshSettings();
bgdColorLBL.BackColor = Properties.Settings.Default.bgdColor;
fontColorLBL.BackColor = Properties.Settings.Default.fontColor;
fontTypeLBL.Font = Properties.Settings.Default.fontType;
fontTypeLBL.Text = Properties.Settings.Default.fontType.Name;
}
private void okBTN_Click(object sender, EventArgs e)
{
LeagueUC lg = new LeagueUC();
InitializeComponent();
this.Close();
}
private void bgdColorLBL_Click(object sender, EventArgs e)
{
ColorDialog dlg = new ColorDialog();
dlg.Color = Properties.Settings.Default.bgdColor;
if (dlg.ShowDialog() == DialogResult.OK)
{
Properties.Settings.Default.bgdColor = dlg.Color;
Properties.Settings.Default.Save();
bgdColorLBL.BackColor = dlg.Color;
}
}
我们看一些代码。也许它只是读取设置并将颜色应用于实际工作的表单加载的实现。 – mortb
如果你需要重绘你有没有尝试'this.Invalidate()'? – Brad
尝试调用InitializeComponent() –