2

I am looking to change the image of the button on the tool strip after it is selected. The image property is system.drawing.bitmap and was saved to Properties\Resources.resx file. Thanks in advancen

An explanation of the logic would be nice too!

Yaron Buki
  • 81
  • 2
  • 12
  • What do you mean by "selected"? Do you want to change the image while the button is clicked, and to alternate between the clicked/unclicked states? – Ilya Kogan Jan 02 '11 at 14:41
  • I have a button that looks like a plus sign, it is to represent add. I would like the image of the button to change to a picture of a disk to be used as a save button after being clicked on. – Yaron Buki Jan 02 '11 at 20:14
  • Why don't you better have two buttons, one with a plus and one with a disk, and at first hide the one with the disk, and after you click the plus, you hide the plus and show the button with the disk? – Andrei Pana Jan 11 '11 at 12:35
  • That is a work around. I wanted change the property, or know if that is a proper method of programing or not. – Yaron Buki Jan 13 '11 at 09:50

3 Answers3

2

First, you should set the CheckOnClick property to true then, it is possible to save the last status of button

this.toolStripMuteButton.CheckOnClick = true;

if (toolStripMuteButton.Checked)
            {
                this._lastMicVol = tag.Volume;
                this.toolStripMuteButton.Image = lobal::Properties.Resources.microphone2;
                tag.Volume = 0;
            }
            else
            {
                this.toolStripMuteButton.Image = global::Properties.Resources.microphone1;
                tag.Volume = this._lastMicVol;
            }
Yasser Bazrforoosh
  • 1,246
  • 10
  • 13
2

The code I found that works is: toolStripButton.Image = Image.FromFile("directory of your file"); During a button click event, just call this code, and the image will change

Dwight
  • 21
  • 2
0

Create an ImageList imageList1; and add the images you require.

To change the toolStripButton image you must do:

toolStripButton1.Image = imageList1.Images[imageIndex];
JKennedy
  • 18,150
  • 17
  • 114
  • 198
Arthur
  • 1