Solved

Toolbar Button Menus

Posted on 2002-07-25
7
229 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
  • 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

828 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