2012-09-10 37 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); 
     } 
    }