【发布时间】:2012-09-03 08:31:47
【问题描述】:
例如,当用户更改背景颜色时,会修改 Settings.settings 文件。它有效。
但在用户单击确定后,应用程序不会更改其背景颜色。 它仅在我关闭并再次构建应用程序时才有效。
如何在单击按钮时重新加载表单或用户控件? (尝试使用 .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;
}
}
【问题讨论】:
-
给我们看一些代码。也许只有读取设置并在表单加载时应用颜色的实现才真正起作用。
-
如果你需要重绘你试过
this.Invalidate()吗? -
尝试调用 InitializeComponent()
-
显示一些代码,因为未知数太多。加上“
It works only when I close and build the application again”——build是什么意思?重新编译? -
@mortb 我添加了一些代码。布拉德和阿特伯德它不起作用。 aleksey.berezan 是的,重新编译