Results 1 to 2 of 2

Thread: toolbar/imagelist problem

  1. #1

    Thread Starter
    Fanatic Member Kaverin's Avatar
    Join Date
    Oct 2000
    Posts
    930
    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 . 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.
    I'm baaaack...
    VB5 Professional Edition, VC++ 6
    Using a 1 gHz Thunderbird, 256 mb RAM, 40 gb HD system with Win98se

    I feel special because I finally figured out how to loop midis: Post link
    I'm a fanatic too

  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,176
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width