2012-09-10 146 views
0

例如,当用户改变背景颜色时,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; 
     } 
    } 
+2

我们看一些代码。也许它只是读取设置并将颜色应用于实际工作的表单加载的实现。 – mortb

+0

如果你需要重绘你有没有尝试'this.Invalidate()'? – Brad

+0

尝试调用InitializeComponent() –

回答

1

运行你有任何代码,在从设置启动文件设置控件的属性。

例如

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(); 

     Settings_Load(null, null); 
    } 
} 
+0

你是什么意思启动? –

+0

请参阅上面的修改。我可能会重新考虑这个,所以你不必用(null,null)参数来调用它。 –

+0

好吧它看起来像它的作品,但我不能称之为另一种形式,因为它不存在。任何想法为什么? –

0

在按钮上单击事件,只需从设置文件中加载背景色。例如:

this.BackColor = Properties.Settings.Default.Color; 
0

您可以为它创建binding。通过一些小窍门,绑定甚至可以允许直接的界面语言切换。

+0

如果你有时间花钱,我准备学习。 –

+0

@DinoVelić恐怕我没有。 – AgentFire

0

试试这个,这改变了颜色形式的背景颜色,你从ColorDialog类选择:

private void button2_Click(object sender, EventArgs e) 
    { 
     ColorDialog dlg = new ColorDialog(); 

     if (dlg.ShowDialog() == DialogResult.OK) 
     { 
      this.BackColor = System.Drawing.Color.FromName(dlg.Color.Name); 
     } 
    }