您的位置:首页 > 编程语言 > C#

C#的winform中MDI 父窗体改变背景色

2011-11-04 10:44 106 查看
http://www.cnblogs.com/kenter/archive/2010/05/26/1744390.html

当您使用一个 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();
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: