views:

63

answers:

2

Hi i have a special request ... I am trying to make a normal button as minimize and exit ... I want three different picture for example button with exit:

1) Stable opened window has exit_1.png

2) When you mose-over it it display exit_2.png

3) When you mouse-leave it display again standard exit_1.png

4) When you press it (click) it display exit_3.png => this situation i dont know how to solve in Visual Basic - Thank you for help.

My code:

Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
    Me.WindowState = FormWindowState.Minimized
    PictureBox1.Image = My.Resources.exit_3
End Sub

Public Sub PictureBox1_MouseHover(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.MouseHover
    PictureBox1.Image = My.Resources.exit_2
End Sub

Public Sub PictureBox1_MouseLeave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.MouseLeave
    PictureBox1.Image = My.Resources.exit_1
End Sub

Picture exit_3 does not display with this code after clicking it. Pictures exit_2 and exit_1 are working fine.

A: 

change the click handler to mousedown and mouseup for swapping images

Private Sub PictureBox1_MouseDown(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.MouseDown
    PictureBox1.Image = My.Resources.exit_3
End Sub

Private Sub PictureBox1_MouseUp(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.MouseUp
    PictureBox1.Image = My.Resources.exit_2
End Sub

and the click handler for the code

Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
    Me.WindowState = FormWindowState.Minimized
End Sub
Soumya92
A: 

MouseLeave is being fired after the Click event, when the form is minimized. The image is set to exit_3 in the Click handler, then immediately back to exit_1 in the Leave handler. Here is one way to fix it:

Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
    Me.WindowState = FormWindowState.Minimized
End Sub

Public Sub PictureBox1_MouseHover(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.MouseHover
    PictureBox1.Image = My.Resources.exit_2
End Sub

Public Sub PictureBox1_MouseLeave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.MouseLeave
    if Me.WindowState = FormWindowState.Minimized then
        PictureBox1.Image = My.Resources.exit_1
    else
        PictureBox1.Image = My.Resources.exit_3
    end if
End Sub
xpda