问题
i need to change the backcolor or background image of a mdi parent in my application. i tried changing the backcolor or specifying a background image, it won't work. i also tried looping the controls in the form to get the mdiclient and change its backcolor, also zero same result.
回答1:
Maybe this will help? http://support.microsoft.com/kb/319465
回答2:
Private ClientControl As MdiClient
Public Sub New()
InitializeComponent()
ClientControl = Nothing
For Each Ctl As Control In Me.Controls
ClientControl = TryCast(Ctl, MdiClient)
If ClientControl IsNot Nothing Then Exit For
Next
End Sub
'iN FORM LOAD
ClientControl.BackColor = Color.Cyan
回答3:
If you are doing a simple colour then try the below code, if you are trying to set an image then you can use BackgroundImage with BackgroundImageLayout
MdiClient ctlMDI;
foreach (Control ctl in this.Controls)
{
try
{
ctlMDI = (MdiClient)ctl;
// Set the BackColor of the MdiClient control.
ctlMDI.BackColor = Color.DarkRed;
}
catch (InvalidCastException exc)
{
// Catch and ignore the error if casting failed.
}
}
回答4:
Try this, it works.
foreach (Control control in this.Controls)
{
// #2
MdiClient client = control as MdiClient;
if (!(client == null))
{
// #3
client.BackColor = GetYourColour();
// 4#
break;
}
}
来源:https://stackoverflow.com/questions/2542972/change-backcolor-or-background-image-of-a-mdi-container-form-in-net