dcsimg
Results 1 to 7 of 7
  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2017
    Posts
    51

    Resolved [RESOLVED] Adding Image to ToolBar Button?

    Hello,

    Firstly, just to clarify, I am using the ToolBar, not the newer ToolStrip. For those who don't know you can add the ToolBar to your form by right clicking on the toolbox and selecting "Select Items..." and then searching for "ToolBar".

    So, I dragged the ToolBar to my form, I then dragged an ImageList to my form. I added images to my ImageList, I pressed 'OK'. I then clicked my ToolBar, went to properties and clicked on the ellipsis (...) on the "Buttons (collection)" field. I added a button, went to 'Image Index' and I can't find the images that I added to my ImageList. Am I doing this wrong? I've checked 238 times that images are indeed added to my ImageList, however I'm still having the problem.

    Is there a solution?

    Thanks for your help! 8)

    PS: I cannot use the ToolStrip; that's not the solution that I'm looking for.

  2. #2
    Fanatic Member
    Join Date
    Aug 2004
    Location
    Essex, UK
    Posts
    548

    Re: Adding Image to ToolBar Button?

    Not sure if this will help, but I just loaded up an old VB6 project that uses a Toolbar and an ImageList. On the property pages of the ImageList you go to the Buttons tab and type an image number in the Image box. This number corresponds to the image number in the ImageList. I assume you do see your images when you go the property pages of the ImageList? This may all be different in .net but it might not be!

  3. #3
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    31,638

    Re: Adding Image to ToolBar Button?

    Nope... it's the same... that's why it's called "ImageIndex" ... it's a number... So you have to know the index of the image you want to use. There is no selector for it otherwise.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  4. #4

    Thread Starter
    Member
    Join Date
    Nov 2017
    Posts
    51

    Re: Adding Image to ToolBar Button?

    Okay, I didn't know you had to search for the Index in the properties. I did it, made sure that the Index value corresponded with the Index of the ImageList. I've done it correctly, this is the designer code that shows that everything should work:

    Code:
     'ToolBarButton1
            '
            Me.ToolBarButton1.ImageIndex = 1
            Me.ToolBarButton1.Name = "ToolBarButton1"
            '
            'ImageList1
            '
            Me.ImageList1.ImageStream = CType(resources.GetObject("ImageList1.ImageStream"), System.Windows.Forms.ImageListStreamer)
            Me.ImageList1.TransparentColor = System.Drawing.Color.Transparent
            Me.ImageList1.Images.SetKeyName(0, "DRAWING.BMP")
            Me.ImageList1.Images.SetKeyName(1, "GROUP.BMP")
            '
    ...And yet it doesn't.

    The code should make the image "GROUP.BMP" appear in the button. It makes no difference if I were to use JPG or PNG.

    Anyone else have any ideas what might be wrong? Thanks.

  5. #5
    Hyperactive Member
    Join Date
    Nov 2017
    Posts
    338

    Re: Adding Image to ToolBar Button?

    The Toolbar itself should have an "ImageList" property that you need to set to the name of the ImageList object that contains the pictures. I think that is all you should need beyond what you have done.

  6. #6

    Thread Starter
    Member
    Join Date
    Nov 2017
    Posts
    51

    Re: Adding Image to ToolBar Button?

    Ah, seems so obvious now, all fixed, thanks!

  7. #7
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    31,638

    Re: [RESOLVED] Adding Image to ToolBar Button?

    1) the toolbar needs to have it's imagelist property set
    2) if I remember right, you need to put images into your imagelist before referencing the index... but I could be wrong.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width


×
We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.