C#的winform中MDI 父表單改變背景色

來源:互聯網
上載者:User
文章目錄
  • 使用 Visual C# .NET 建立一個樣本 Windows 應用程式
  • 使用 Visual C# .NET 建立一個樣本 Windows 應用程式
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();
當您使用一個 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();

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.