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
 
 
 
 
 
TitleGive an MDIForm a resizing background picture
KeywordsMDI, background, draw, MDIForm
CategoriesGraphics, Tips and Tricks
 
Store the original picture in a PictureBox. When the form resizes, use PaintPicture to copy it into a new PictureBox with the same size as the MDIForm. Then copy its Picture property to the MDIForm.

Thanks to Shashikant Patil for figuring out that the code needs to invalidate the MDI window.

 
' Make the image fit the MDI form.
Private Sub MDIForm_Resize()
Dim client_rect As RECT
Dim client_hwnd As Long

    picStretched.Move 0, 0, _
        ScaleWidth, ScaleHeight

    ' Copy the original picture into picStretched.
    picStretched.PaintPicture _
        picOriginal.Picture, _
        0, 0, _
        picStretched.ScaleWidth, _
        picStretched.ScaleHeight, _
        0, 0, _
        picOriginal.ScaleWidth, _
        picOriginal.ScaleHeight
        
    ' Set the MDI form's picture.
    Picture = picStretched.Image

    ' Invalidate the picture.
    client_hwnd = FindWindowEx(Me.hwnd, 0, "MDIClient", _
        vbNullChar)
    GetClientRect client_hwnd, client_rect
    InvalidateRect client_hwnd, client_rect, 1
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated