-
I've been working on a program where I have an MDI form with a toolbar and an imagelist control with all the button bitmaps (and some other bitmaps) in it. At first I set up the buttons and such at design time, but after about the 5th time I wanted to add an image and had to reset the buttons again since you can't add images to the control when it's bound to something else. I decided to do the assignments in code afterwards, and thought this would work:
Code:
'this is in a module btw
Public Sub LoadToolbarIcons()
Dim Button As ComctlLib.Button
Set mdiText.tbrTools.ImageList = mdiText.imlToolbarIcons
For Each Button In mdiText.tbrTools.Buttons
If Button.Key <> "" Then mdiText.tbrTools.Buttons(Button.Key).Image = mdiText.imlToolbarIcons.ListImages(Button.Key).Picture
Next Button
End Sub
When this runs, I'll get an error about invalid keys (each of my buttons has a key, and has a matching key in the imagelist control for the proper bitmap). I can't tell why it's doing that though :confused:. If I manually use code to set things from the imagelist, it works fine. Some of my buttons have the separator style, so they don't have keys, which is why I make sure they do have keys in that sub. Does anyone know what might be going on? I feel I've missed something simple.
-
When assigning an Image to a Toolbar button you only pass the Key in the ImageList, not the Picture, i.e.
Code:
Public Sub LoadToolbarIcons()
Dim Button As ComctlLib.Button
Set mdiText.tbrTools.ImageList = mdiText.imlToolbarIcons
For Each Button In mdiText.tbrTools.Buttons
If Button.Key <> "" Then Button.Image = Button.Key
Next Button
End Sub