0

たとえば、ユーザーが背景色を変更すると、Settings.settings ファイルが変更されます。そして、それは機能します。

ただし、ユーザーが [OK] をクリックした後、アプリケーションは背景色を変更しません。アプリケーションを閉じて再度ビルドした場合にのみ機能します。

ボタンのクリック時にフォームまたはユーザー コントロールをリロードするにはどうすればよいですか? (.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;
        }
    }
4

4 に答える 4

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);
    } 
} 
于 2012-09-10T13:06:35.793 に答える
0

バインディングを作成できます。ちょっとしたトリックで、バインディングはインターフェース言語の即時切り替えを可能にすることさえできます。

于 2012-09-10T13:18:20.070 に答える
0

ボタンクリックイベントで、設定ファイルから背景色をロードするだけです。何かのようなもの:

this.BackColor = Properties.Settings.Default.Color;
于 2012-09-10T13:10:25.477 に答える
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);
        }
    }
于 2012-09-10T14:00:54.067 に答える