|
-
Nov 10th, 2007, 12:00 AM
#1
Changing the Background of an MDI Parent Form
C# version here.
I've posted a solution to this question many times already and it's come up again recently, so I figured a little CodeBank submission might be helpful. First, some background information:
When you set the IsMdiContainer property of a form to True, the IDE adds an MdiClient control to your form. The grey background you see is not the form but the MdiClient control. If you set the BackColor or BackgroundImage properties of the form it will have no effect because you can't see the form's background.
Now, it is actually this MdiClient control, not the form itself, that hosts the MDI child forms. If you add any controls to the parent form then they will either be behind the MdiClient and, therefore, not visible or else on top of the MdiClient and, therefore, on top of the MDI child forms too.
The developer is not intended to mess with this MdiClient control so no member variable is provided with which to access it. It's not inaccessible though, so if you want to change the visible background of the parent form you can do this:
VB.NET Code:
Private Sub Form1_Load(ByVal sender As Object, _ ByVal e As EventArgs) Handles MyBase.Load For Each ctl As Control In Me.Controls If TypeOf ctl Is MdiClient Then 'Set properties of ctl here, e.g. ctl.BackgroundImage = My.Resources.MdiBackgroundImage Exit For End If Next ctl End Sub
Last edited by jmcilhinney; Oct 30th, 2008 at 04:57 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|