Machaira's Blog

Jim Perry's Blog at vbCity

This blog hosted by:
http://blogs.vbcity.com      
  Home :: Syndication  :: Login

SepOctober 2008Nov
SMTWTFS
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678

Articles

Archives

.NET Development Links

Game Development Links

Miscellaneous Links

I've been seeing a lot of posts in the vbCity forums lately about working with the client area of an MDI form. What's not immediately obvious is that the client area is actually an MdiClient control for the forms that are children of the MDI form (not the controls you put on an MDI form. They go into the form's Controls collection). One question I saw was asking how to change the backcolor of the client area. Doing:

Me.BackColor = Color.Red

doesn't work since it changes the BackColor of the form, not the client area control. To do that you would do:

Me.Controls(Me.Controls.Count - 1).BackColor = Color.Red

Note that the client area control is always the last item in the Controls collection. Since the MdiClient derives from the Control class you can do a lot of things with it that you can do with any other control. For instance, another question asked how to make the client area of an MDI form fill with a gradient. The solution is to override the Paint event of the MdiClient control (not the form's Paint event since, again, that would be hidden behind the MdiClient control):

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

        AddHandler Me.Controls(Me.Controls.Count - 1).Paint, AddressOf PaintMDI

    End Sub

    Private Sub PaintMDI(ByVal sender As Object, ByVal e As PaintEventArgs)

        Dim rect As New Rectangle(0, 0, sender.Width, sender.Height)
        Dim lBrush As LinearGradientBrush = New LinearGradientBrush(rect, Color.Blue, Color.Green, LinearGradientMode.Vertical)
        e.Graphics.FillRectangle(lBrush, rect)
       

    End Sub

posted on Wednesday, April 05, 2006 1:35 PM