' Make the button display the picture beneath it.
Private Sub SetButtonBackground(ByVal btn As CommandButton, _
ByVal txt As String)
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
' Add text to the image.
' Code Added by DiamondGeo to Include Text on Buttons
' Thanks to DiamondGeo <diamondgeo@diamondgeo.org>.
picHidden.CurrentX = _
(wid - picHidden.TextWidth(txt)) / 2
picHidden.CurrentY = _
(hgt - picHidden.TextHeight(txt)) / 2
picHidden.Print txt
picHidden.Picture = picHidden.Image
' Set the button's picture.
btn.Picture = picHidden.Picture
End Sub
|