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
 
 
 
 
 
TitleMake buttons display the picture under them
Keywordsbutton, picture, tile
CategoriesControls, Graphics
 

Use GetSystemMetrics to get the button's border thickness. Use that value and the button's position to determine what part of the underlying picture it covers. Use PaintPicture to copy that part of the underlying picture into a hidden PictureBox. Finally, set the button's Picture to that picture.

 
' Make the button display the picture beneath it.
Private Sub SetButtonBackground(ByVal btn As CommandButton)
Dim wid As Single
Dim hgt As Single
Dim xoff As Single
Dim yoff As Single

    ' Get the button size.
    wid = btn.Width
    hgt = btn.Height

    ' Get the button's border thickness.
    xoff = GetSystemMetrics(SM_CXFIXEDFRAME)
    yoff = GetSystemMetrics(SM_CYFIXEDFRAME)

    ' Size the hidden PictureBox to fit the button.
    picHidden.Move 0, 0, wid, hgt

    ' Copy the picture under the button to the PictureBox.
    picHidden.PaintPicture Picture, 0, 0, wid, hgt, _
        btn.Left + xoff, btn.Top + yoff, wid, hgt
    picHidden.Picture = picHidden.Image

    ' Set the button's picture.
    btn.Picture = picHidden.Picture
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated