none
How do I connect a ToolStripMenuItem with a Picturebox? RRS feed

  • Question

  • There are three ToolStripMenuItem's, I need to link these three to a Picturebox. When the program is running and you hover the pointer over each ToolStripMenuItem, a different image appears in the picturebox. I have no idea how to do this, please help!
    Friday, March 16, 2018 7:56 PM

All replies

  • Once you've created the ToolStrip in the designer and added the buttons, there will be code objects for each button according to their names (eg ToolStripButton1).

    In code you can add a handler to the ToolStripButton.MouseHover event and in that event handler code you can set the button's Image property to whatever you need.


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    • Proposed as answer by Mr. Monkeyboy Saturday, March 17, 2018 9:02 PM
    Friday, March 16, 2018 8:35 PM
    Moderator
  • Hi

    EDIT: sorry Reed, didn't see your reply until I posted mine.

    An example for a ToolStripMenu with a couple of items (Two & Three)

      Private Sub TwoToolStripMenuItem_MouseHover(sender As Object, e As EventArgs) Handles TwoToolStripMenuItem.MouseHover
    	' load picture for menu item 'Two'
      End Sub
      Private Sub ThreeToolStripMenuItem_MouseHover(sender As Object, e As EventArgs) Handles ThreeToolStripMenuItem.MouseHover
    	' load picture for menu item 'Three'
      End Sub


    Regards Les, Livingston, Scotland



    • Edited by leshay Friday, March 16, 2018 8:38 PM
    • Proposed as answer by Mr. Monkeyboy Saturday, March 17, 2018 9:02 PM
    Friday, March 16, 2018 8:37 PM
  • This works for ToolStripButtons. I didn't try for any ToolStripMenu items though.

        Private Sub ToolStripButtons_MouseHover(sender As Object, e As EventArgs) Handles ToolStripButton1.MouseHover, ToolStripButton2.MouseHover, ToolStripButton3.MouseHover
            Select Case DirectCast(sender, ToolStripButton).Name
                Case Is = "ToolStripButton1"
                    PictureBox1.Size = My.Resources.Crossbones_Png.Size
                    PictureBox1.Image = My.Resources.Crossbones_Png
                    PictureBox2.Image = Nothing
                    PictureBox3.Image = Nothing
                Case Is = "ToolStripButton2"
                    PictureBox2.Size = My.Resources.Moon1.Size
                    PictureBox2.Image = My.Resources.Moon1
                    PictureBox1.Image = Nothing
                    PictureBox3.Image = Nothing
                Case Is = "ToolStripButton3"
                    PictureBox3.Size = My.Resources.Shield.Size
                    PictureBox3.Image = My.Resources.Shield
                    PictureBox1.Image = Nothing
                    PictureBox2.Image = Nothing
            End Select
        End Sub


    La vida loca

    Saturday, March 17, 2018 9:39 PM