Copy the Desktop Wallpaper to your Form's Background

Its simple to copy the desktop wallpaper to your form's background or to any control with a device context handle (such as a picture box). All it takes is a single line of code which calls the PaintDesktop API.

Download Source Code

Form Code

Copy the following code to the Declarations section of a Form:

Private Declare Function PaintDesktop Lib "user32" (ByVal hdc As Long) As Long

Copy the following code to the Form's Paint Event:

'
' The PaintDesktop function fills the clipping region in the specified
' device context with the desktop pattern or wallpaper. The
' function is provided primarily for shell desktops.
'
Private Sub Form_Paint()
    PaintDesktop Me.hdc
End Sub

   '
   ' The PaintDesktop function fills the clipping region in the specified
   ' device context with the desktop pattern or wallpaper. The
   ' function is provided primarily for shell desktops.
   '
   Private Sub Form_Paint()
      PaintDesktop Me.hdc
   End Sub

 

Instructions

Download this project and run it. Resize the form to better view the wallpaper which was added to the form's background.




About TheScarms
About TheScarms


Sample code
version info

If you use this code, please mention "www.TheScarms.com"

Email this page


© Copyright 2024 TheScarms
Goto top of page