Change the MdiContainer back color

Heres your chance to share your own tutorials with the community. Just post them on here. If your lucky they may even be posted on the main site.
3 posts Page 1 of 1
Contributors
User avatar
smashapps
Coding Guru
Coding Guru
Posts: 961
Joined: Tue Apr 05, 2011 8:41 am

Have you used an Mdi form before? If you have you will have noticed the ugly gray container, you cannot just change the backColor of the form, it will stay gray.

Here is a tutorial i have made to show how you can change it, and of course explain most of the code, with source code and an image :)

Create a new project, You don't need to add any controls or change any properties I did it all by code.

on for the Form1 load event add this:
Code: Select all

Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        'Here we are declaring a new form, not needed but you can see what the Mdi container is, and of course declare out mdicontainer
        Me.IsMdiContainer = True
        Dim testform As New Windows.Forms.Form
        testform.Text = "Test Form"
        testform.Width = 300
        testform.Height = 300
        testform.MdiParent = Me
        testform.Show()

        'now we are gonig to use a loop to change the backcolor of the mdi container
        'you cannot just change the forms backcolor, it wont work for the container, it will stay gray
        For Each MdiContainer As Control In Me.Controls
            If TypeOf MdiContainer Is MdiClient Then
                MdiContainer.BackColor = Color.Azure
                'You can change the color to any that you wish, and you can use an image, code below
                'MdiContainer.BackgroundImage = Image.FromFile("Image Path")
                'If your image has a transparent background, the back color will be to what ever you have set it to
            End If
        Next MdiContainer

        'make the mdiparent double buffered so there isnt any flickering etc with the child form
        Me.DoubleBuffered = True
    End Sub

I created a ChildForm so you can see what the MdiContainer actually does, to change the backcolor or back image we use a loop. Everything that is an MdiClient will then have the backColor changed to Color.Azure, I also showed how to change the image but commented it, if you want to use an image just remove the ' from the start of MdiContainer.BackgroundImage

Image:

Image

If you liked my tutorial feel free to +rep me and if have any questions or anything I will be glad to try and answer them :)
Source code:
You do not have the required permissions to view the files attached to this post.
My name is Tom | Visit my blog where I post new content every day! Tom's Daily Blog | MineCraft is awesome!
User avatar
hungryhounduk
VIP - Site Partner
VIP - Site Partner
Posts: 2870
Joined: Mon Jul 27, 2009 11:58 am

Hey Smash

Excellent Tutorial again

keep it up

Chris
Image
User avatar
smashapps
Coding Guru
Coding Guru
Posts: 961
Joined: Tue Apr 05, 2011 8:41 am

I'm out of ideas now though and thanks :)
My name is Tom | Visit my blog where I post new content every day! Tom's Daily Blog | MineCraft is awesome!
3 posts Page 1 of 1
Return to “Tutorials”