Link to home
Start Free TrialLog in
Avatar of Clif
ClifFlag for United States of America

asked on

Toolbar Button Menus

I'm attemping to create something similar to the "Fill Color" button in Excel.

For those who don't know, the "Fill Color" button has an image of a paint can with a bar in the currently selected fill color.  Clicking on the drop-down arrow shows a pallet which allows you to select the fill color.

My problem is in setting the image of the button to the correct image.  I know I can fill up the image list control which is attached to the tool bar, but I'd rather have a separate image list with just the fill color icons, which I then assign to the "Fill Color" button.

I can't get the button's image to change, though.

Here is the code I'm trying to use:

Private Sub tbrMain_ButtonMenuClick(ByVal ButtonMenu As MSComctlLib.ButtonMenu)
    imlMain.ListImages(16).Draw imlFillColor.ListImages(ButtonMenu.Index).Picture, , , imlNormal
    g_sFillColor = ButtonMenu.Key
End Sub

Basically, why doesn't this work, and how can I make it work?
Avatar of ventond
ventond
Flag of United States of America image

The first parameter of the .Draw method is WHERE to draw, not WHAT to draw. The What is handeled by .ListImages(16).

The Where is a device context of the item you want to draw on. Usually Form1.hdc or similar. Does the ButtonMenu have an .hdc property?

Avatar of Clif

ASKER

So, you're saying that it should be:

    imlFillColor.ListImages(ButtonMenu.Index).Draw imlMain.ListImages(16).Picture, , , imlNormal

Unfortunately the "Picture" object doesn't have a hDC property (not exposed, at any rate).
Avatar of Richie_Simonetti
you can get dc with GetDc API, then
dim hdcpic as long
hdcPic=GetDC(picture1.hwnd)
Avatar of Clif

ASKER

Unfortunately the Picture object of the ImageList control doesn't have an hWnd property either.
Sorry, very sorry. I don't know what i was thinking... I must read question before post anything... :D
ASKER CERTIFIED SOLUTION
Avatar of ventond
ventond
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Clif

ASKER

Sorry it took so long to grade, but I lost this.  :)

At any rate, I went with multiple images in the image list.