Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


How to draw a picture on a command button

Posted on 1999-07-12
Medium Priority
Last Modified: 2010-05-02
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?
Question by:wiltonk
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Expert Comment

ID: 1524126
I can give you some source to make a button from two image controls. Substitute picture boxes and you can draw on it.

Accepted Solution

JustinB earned 800 total points
ID: 1524127
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question ( in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question