[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 743
  • Last Modified:

.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?
0
tsmolskow
Asked:
tsmolskow
  • 3
  • 2
1 Solution
 
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
 
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
 
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

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now