zoukankan      html  css  js  c++  java
  • C#的winform中MDI 父窗体改变背景色

    当您使用一个 Windows 窗体作为一个 MDI 父窗体时, 在 Windows 控制面板,不窗体的 BackgroundColor 属性, 应用程序背景 颜色设置确定窗体的背景颜色。 下面的步骤演示了如何以编程方式在 MDI 父窗体的背景色更改为另一种颜色。

    使用 Visual C# .NET 创建一个示例 Windows 应用程序

    1. 创建一个新的 Visual C# Windows 应用程序。 默认情况下会创建 Form 1。
    2. 单击窗体,然后,在 视图 菜单上,选择 属性窗口 以查看为窗体属性。
    3. 背景色 属性设置为所需 (如 LightBlue ) 颜色。
    4. IsMDIContainer 属性设置为 True 。 请注意窗体的背景色更改为控制面板中 应用程序背 景色设置为的颜色。
    5. WindowState 属性设置为 Maximized
    6. 双击窗体查看它的代码窗口。
    7. 将下面的代码粘贴到窗体的 Load 事件处理程序:
    MdiClient ctlMDI;
    
    // Loop through all of the form's controls looking
    // for the control of type MdiClient.
    foreach (Control ctl in this.Controls)
    {
       try
       {
          // Attempt to cast the control to type MdiClient.
          ctlMDI = (MdiClient) ctl;
    
          // Set the BackColor of the MdiClient control.
          ctlMDI.BackColor = this.BackColor;
       }
       catch (InvalidCastException exc)
       {
          // Catch and ignore the error if casting failed.
       }           
    }
      
    // Display a child form to show this is still an MDI application.
    Form2 frm = new Form2();
    frm.MdiParent = this;
    frm.Show();
  • 相关阅读:
    C语言I博客作业03
    C语言I—2019秋作业02
    C语言I博客作业04
    C语言I博客作业02
    C语言I博客作业02
    C语言I博客作业04
    C语言I博客作业02
    C语言I博客作业02
    第一周作业
    C语言I博客作业04
  • 原文地址:https://www.cnblogs.com/kenter/p/1744390.html
Copyright © 2011-2022 走看看