• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 239
  • Last Modified:

How to draw a picture on a command button

I want to draw a picture on a command button. But the graphic mode is not fulfill my requirement since I want to put anywhere of the button by sending the x, y coordinate. Is there any way or API to do that?
1 Solution
I can give you some source to make a button from two image controls. Substitute picture boxes and you can draw on it.
This will put a picture stored as a pic control somewhere on your form on the button. The picturebox can be hidden i.e. visible set to false but the autoredraw property must be set to true.

' This do events is necessary - otherwise the bitmap does not appear
    BitBlt GetDC(cmdbutton.hwnd), 5, 5, picHidden.Width, picHidden.Height, picHidden.hDC, 0, 0, SRCCOPY

You will need to put this code in other events if you want
the picture to remain. Place it in form load, cmdbutton_lostfocus, and cmdbutton_click

The doevents may or may not be necessary before each call to bitblt but try it with first.

Here are the API declares you will need

Public Const SRCCOPY = &HCC0020

Public Declare Function BitBlt Lib "gdi32" Alias "BitBlt" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long

Hope that helps.


Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now