我想设置一个父窗体,其它窗体继承这一窗体,这样用来设置窗体颜色的个性化,但窗体上的其它控件则挡住了一部分,这样看起来很难看,把控件设置成透明色太麻烦,也不好,请问有没有一个很好的解决办法

解决方案 »

  1.   

    步骤
    1:创建两个窗体
    2:将第一窗体的IsMdiContainer的属性设置成true;
    3: 在第一窗体的Form_Load编程
    private void Form1_Load(object sender, System.EventArgs e)
    {
    Form2 frm2=new Form2();
    frm2.MdiParent=this;
    frm2.Show();
    }
    这样第二个窗体就是第一个窗体子窗体。
    如果要多个窗体继承父窗体是同样的方法,要将窗体实例化。
      

  2.   

    在外部定义一个静态方法
    比如public static void SetSkin(Form form)
    这里对窗体属性赋值然后在FROM里面
    public override void Refresh()
            {
                FormUtil.SetSkin(this);
                base.Refresh();
            }
      

  3.   

    public static void SetSkin(Form form)里面可以这么写
    foreach (object control in form.Controls)
                    {
                        if (control is TabControl)
                        {
                            int sums = ((TabControl)control).TabPages.Count;
                            for (int i = 0; i < sums; ++i)
                            {
                                ((TabControl)control).TabPages[i].BackColor = skin.BackColors;
                            }
                        }
                        if (control is Button)
                        {
                            ((Button)control).BackColor = skin.ButtonColor;
                            ((Button)control).ForeColor = skin.ButtonFontColor;
                        }
                        if (control is CustomControl.ButtonCustom)
                        {
                            ((CustomControl.ButtonCustom)control).BackColor = skin.ButtonColor;
                            ((CustomControl.ButtonCustom)control).ForeColor = skin.ButtonFontColor;
                        }
                        if (control is CustomControl.CustomButtonAngle)
                        {
                            ((CustomControl.CustomButtonAngle)control).BackColor = skin.ButtonColor;
                            ((CustomControl.CustomButtonAngle)control).ForeColor = skin.ButtonFontColor;
                        }
                        if (control is CustomControl.CustomControlForm)
                        {
                            ((CustomControl.CustomControlForm)control).BackColor = skin.BackColors;
                        }
                        if (control is Panel)
                        {
                            ((Panel)control).BackColor = skin.BackColors;
                        }
                        if (control is TextBox)
                        {
                            ((TextBox)control).ForeColor = skin.TextFontColor;
                            ((TextBox)control).BackColor = skin.TextColor;
                        }
                        if (control is ComboBox)
                        {
                            ((ComboBox)control).ForeColor = skin.TextFontColor;
                            ((ComboBox)control).BackColor = skin.TextColor;
                        }
                        if (control is Label)
                        {
                            ((Label)control).BackColor = skin.BackColors;
                            ((Label)control).ForeColor = skin.FontColor;
                        }
                        if (control is RadioButton)
                        {
                            ((RadioButton)control).ForeColor = skin.RadioButtonBackColor;
                            ((RadioButton)control).BackColor = skin.BackColors;
                        }
                    }
      

  4.   

    谢谢老师
    skin是类对象吗?
    control is TabControl:的意思是不是“控件是否是能接受TAB的控件”