Solved

Toolbar Button Menus

Posted on 2002-07-25
7
243 Views
Last Modified: 2010-05-02
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?
0
Comment
Question by:Clif
[X]
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
  • 3
  • 2
  • 2
7 Comments
 
LVL 2

Expert Comment

by:ventond
ID: 7177678
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?

0
 
LVL 10

Author Comment

by:Clif
ID: 7177775
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).
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7177896
you can get dc with GetDc API, then
dim hdcpic as long
hdcPic=GetDC(picture1.hwnd)
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 10

Author Comment

by:Clif
ID: 7180049
Unfortunately the Picture object of the ImageList control doesn't have an hWnd property either.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7180112
Sorry, very sorry. I don't know what i was thinking... I must read question before post anything... :D
0
 
LVL 2

Accepted Solution

by:
ventond earned 100 total points
ID: 7181467
You can't draw onto an image list control because the image list control has no visible component.

I played with button menus and what I think you are going to do is something like:

Toolbar.Buttons(button.index).image = [index of colored pic]



I say this because you aren't drawing the picture. You are trying to tell the toolbar what picture to draw. The toolbar looks in a List Image control for the pictures to show. If you want to draw the color you will have to catch every repaint/refresh event to redraw everytime. Special note, ALL of the images that you want the toolbar to use must be in one List image control.

I am not at a computer that I can test this at the moment so I hope the Image property is available in the collection.

0
 
LVL 10

Author Comment

by:Clif
ID: 7350791
Sorry it took so long to grade, but I lost this.  :)

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

Featured Post

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) 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…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…

691 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