文章目錄
- 使用 Visual C# .NET 建立一個樣本 Windows 應用程式
- 使用 Visual C# .NET 建立一個樣本 Windows 應用程式
C#的winform中MDI 父表單改變背景色當您使用一個 Windows 表單作為一個 MDI 父表單時, 在 Windows 控制台,不表單的
BackgroundColor 屬性,
應用程式背景 顏色設定確定表單的背景顏色。 下面的步驟示範了如何以編程方式在 MDI 父表單的背景色更改為另一種顏色。 使用 Visual C# .NET 建立一個樣本 Windows 應用程式
- 建立一個新的 Visual C# Windows 應用程式。 預設情況下會建立 Form 1。
- 單擊表單,然後,在 視圖 菜單上,選擇 屬性視窗 以查看為表單內容。
- 將 背景色 屬性設定為所需 (如 LightBlue ) 顏色。
- 將 IsMDIContainer 屬性設定為 True 。 請注意表單的背景色更改為控制台中 應用程式背 景色設定為的顏色。
- 將 WindowState 屬性設定為 Maximized 。
- 雙擊表單查看它的代碼視窗。
- 將下面的代碼粘貼到表單的 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 應用程式
- 建立一個新的 Visual C# Windows 應用程式。 預設情況下會建立 Form 1。
- 單擊表單,然後,在 視圖 菜單上,選擇 屬性視窗 以查看為表單內容。
- 將 背景色 屬性設定為所需 (如 LightBlue ) 顏色。
- 將 IsMDIContainer 屬性設定為 True 。 請注意表單的背景色更改為控制台中 應用程式背 景色設定為的顏色。
- 將 WindowState 屬性設定為 Maximized 。
- 雙擊表單查看它的代碼視窗。
- 將下面的代碼粘貼到表單的 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();