改变一切形式的背景色在WinForm应用程序 [英] Changing background color of all forms in winform application

查看:203
本文介绍了改变一切形式的背景色在WinForm应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有基本形式类像这样为继承Form类

I have BaseForm Class like this that is inheriting Form Class

 public partial class BaseForm : Form
 {
    protected override void OnLoad(EventArgs e)
    {
       Color colBackColor =Properties.Settings.Default.FormsBackgroundColor;
       BackColor = colBackColor;
    }
  }

和MainForm类这样是继承基本形式类。

and MainForm class like this which is inheriting BaseForm Class.

public partial class MainForm : BaseForm
{
    private void button1_Click_1(object sender, EventArgs e)
    {
            ColorDialog colorDlg = new ColorDialog();
            if (colorDlg.ShowDialog() == DialogResult.OK)
            {
                Properties.Settings.Default.FormsBackgroundColor= colorDlg.Color;
                Properties.Settings.Default.Save();
                this.Refresh();
                this.Invalidate();
            }
        }    
 }

当我点击按钮1上的MainForm然后从颜色对话框颜色。 MainForm的的背景颜色不发生变化。我做错了吗?

When i click button1 on MainForm and choose color from the color dialog. The background color of MainForm doesn't change. What I am doing wrong?

顺便说一下颜色的变化,当我重新运行该应用程序。

Btw color changes when i re-run the application.

推荐答案

的OnLoad 事件只触发加载窗体时,它的确,当你点击按钮不会被触发。所以,你需要改变窗体背景色的 button1_Click_1 也。

The OnLoad event is only triggered when the form loads, it doesn't get triggered when you click the button. So you need to change the form BackColor in button1_Click_1 also.

if (colorDlg.ShowDialog() == DialogResult.OK)
{
    Properties.Settings.Default.FormsBackgroundColor= colorDlg.Color;
    Properties.Settings.Default.Save();
    this.BackColor = colorDlg.Color;
}

这篇关于改变一切形式的背景色在WinForm应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆