Missing events handler

DarkKai

Newcomer
Joined
Jan 6, 2005
Messages
2
Hi, I'm having some problems with picturebox events in VB.net.
I've 2 forms

Main form (Form1) :
1 button

Second form(Form2) :
1 picturebox

Main form code

Dim TESTForm As New Form2

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

TESTForm.ShowDialog(Me)
End Sub

Second form code

Friend Sub PictureBox1_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox1.MouseEnter
PictureBox1.Image = New Bitmap("C:\Documents and Settings\kevin\Desktop\Cuttool\01ok_small_h.png")
End Sub

Friend Sub PictureBox1_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox1.MouseLeave
PictureBox1.Image = New Bitmap("C:\Documents and Settings\kevin\Desktop\Cuttool\01ok_small_n.png")
End Sub

Private Sub PictureBox1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
Me.Hide()
End Sub

The problem :
the code works fine the first time where my picture box will change image each time my mouse hover in and out.
But after i clicked on the picturebox to hide the form(Form2) and reload it by clicking on the button on Form1, I kindda lost my mouseEnter and mouseLeave events for the picturebox. Funny thing is i can still get my click event for the picturebox.
Is this a bug or am i doing something wrong here?
Thanks in advance :)
 
I ran into some issues like this once as well. I don't quite remember all the ins and outs of the order events fire and what causes them (or doesn't cause them) so my recommendation is that you make a little experiment. Put some console.writeline statements in the events and set up event handlers for a few events, like mouse enter, moust leve, mouse click, etc... Maybe even one for when your form has focus and things like that. Each writeline shoulds say something like "Form1 - mouse enter" or something that allows you to uniquely identify the specific event handler.

After you have the writelines in there you'll be able to see exactly what is happening in your program. You can't debug, becuase if your mouse was over the box, as soon as the debugger kicks in you'll no longer be over it, thus firing another event.

Use the writelines to really see what is happening. It will give you a better idea of how things are working, what causes them, and the order in whch they happen.
 
Back
Top