.NET 2.0 with toolstrip

I'm using .NET 2.0 with a tooltsrtip in a form.  I have added a button to the tool strip, and I used the image property to assign a image to the button.  Now I want to create a pressed in pushed out effect with two different images.  My question is, how do I dynamically change the image associated with the button on the toolstrip?
tsmolskowAsked:
Who is Participating?
 
nayernaguibCommented:
This depends on whether you would like to display a different image *while* the button is being clicked, or you would like to change the image with every click (change the state of the button until it is pressed again).

To change the image everytime the button is checked/unchecked, you should set the CheckOnClick property of the button to true, and add the following code to the Click event handler of the *button* (not the ToolStrip):

            if (myToolStripButton.Checked)
                myToolStripButton.Image = someImage;
            else
                myToolStripButton.Image = theOtherImage;

If you want to change the image *while* the button is being pressed, then I'll need to give it a try and come back to you. :-)

_______________

  Nayer Naguib
0
 
nayernaguibCommented:
Use the following statement:

            myToolStrip.Items(index).Image = System.Drawing.Image.FromFile("filePath") 'or any other image source

_______________

  Nayer Naguib
0
 
tsmolskowAuthor Commented:
Right, I guess I didn't write my question well, I wanted the flow logic code to be able to switch back and forth between images, right now I'm using a resource file and this code to change images:

toolStripButton4.Image = Prototype.Properties.Resources.PushPin_Selected.png;

But i'm not sure of the logic I need to switch the pin images from selected to unselected and back based on the click event
0
 
tsmolskowAuthor Commented:
It's not working, here's my code:

     private void toolStripButton4_Click(object sender, EventArgs e)
     {
 
            if (toolStripButton4.Checked)
            {
                toolStripButton4.Image = Prototype.Properties.Resources.color_tab_enemy_selected;
            }
            else
            {
                toolStripButton4.Image = Prototype.Properties.Resources.color_tab_enemy_unselected;
            }
     }


   Am I missing a setting on the control?
0
 
tsmolskowAuthor Commented:
OK, I found it, I had to set the CheckOnClick event to true - thanks again Nayer
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.