Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleChange the color of an MDI parent form's background
DescriptionThis example shows how to change the color of an MDI parent form's background in VB .NET.
KeywordsMDI, MDI parent, background, background image, VB.NET
CategoriesVB.NET, Controls
 
See Knowledge Base article 319417: HOW TO: Change the Background Color for an MDI Parent Form in Visual Basic .NET, although this version is better because it doesn't need a Try Catch block.

When the MDI parent form loads, it searches its child controls for the one that is an MdiClient. It sets that control's BackColor property to match the form's, which is set at design time.

 
Private Sub Form1_Load(ByVal sender As System.Object, ByVal _
    e As System.EventArgs) Handles MyBase.Load
    ' Set the color in the MDI client.
    For Each ctl As Control In Me.Controls
        If TypeOf ctl Is MdiClient Then
            ctl.BackColor = Me.BackColor
        End If
    Next ctl

    ' Display a child form.
    Dim frm As New Form2
    frm.MdiParent = Me
    frm.Width = Me.Width \ 2
    frm.Height = Me.Height \ 2
    frm.Show()
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated