Visual Basic ToolBar and ImageList

Athono

Member
Joined
Jan 10, 2006
Messages
5
Programming Experience
Beginner
I am new to Visual Basic. So the differences between C++ and VB are striking to me. But even this seems like too much. Here is what I am talking about:

I got a project out of source safe and I started working with it.
The Graphics associated to an image list had been compiled into the project but the actual graphic files were missing.
So they appeared in the project at first but then the buttons associated with the image list went blank.
I thought all I had to do was to get the graphic image files and then reassign the image list and the toolbar. But NOOOOO. According to the book I have, once the image is set, you cannot change it and you will have to build the entire thing from scratch.

Is this right?

------------------------------

OK, so I went ahead and wrote down all the key names and other data associated with the image list and the button bar and I went ahaead and deleted them. I have made a back-up copy of the project in case I want to go return to the version before I did this.

But now, after inserting each bitmap into the ImageList, I right-clicked on the new Toolbar and choose Properties and assigned it the ImageList.

Now, aren't the images supposed to pop into the toolbar?

What am I doing wrong?
 
I'm not sure exactly how you are doing things at the moment. If you add an ImageList to a form in the designer and then add Images to it, those Images will become resources in the project. Even if you delete the original files it should not make a difference as there is no dependence on the original files in this situation. Once you've created the ImageList you would assign it to the ToolBar's ImageList property. You would then set the ImageIndex of each ToolBarButton and that should be it. If you have enabled visual styles (WinXP theming) then you need to make sure you call Application.DoEvents AFTER calling Application.EnableVisualStyles and BEFORE calling Application.Run. Note that thsi advice applies to VS.NET 2003. You say "ToolBar" so I assume that that is your version. VS 2005 supports the ToolStrip control which is much more versatile and relatively different.
 
I got the buttons (their graphic image) back to the toolbar.
And when you click on the buttons, the right VB code is executed through a switch statement, etc.

So I am just about there.

The only problem now is that when I click on a button, it does not stay clicked. Any idea why that is? I looked at the properties of the toolbar but I cannot find any sort of thing that suggests that a button should stay down once you click it.

In other words, when the toolbar comes up, the first button appears as being pressed down. And if a user clicks on any other buttons, he can do so, but once he let's go, the first button goes back to being the only one pressed down.
 
The standard behaviour for a ToolBarButton is to behave just like a regular Button, as you have seen. If you want them to remain depressed you need to set the Style property to ToggleButton instead of PushButton. Note that depressing one button will not implicitly cause any others to pop up. To do that you would have to write code to set the Pushed property of all the other buttons to False.
 
Back
Top