Open File Dialog and Picturebox Click Event

M

Mattbooty

Hello,
Not sure if anyone else has seen this bug, but I have a form where
the entire form is covered with a picturebox. The picturebox has a
mouseup event. I also have an open file dialog for loading images into
the picturebox. If you double click the file you want to open in the
open file dialog, it somehow interperets one of the clicks as a mouseup
on the picturebox and fires the mouseup event for the picturebox. How
can I get around this? I tried disabling the picturebox before loading
the dialog and enabling it after I complete loading the file, but it
still fires the mouseup event.

Any thoughts would be a big help!
 
P

Peter Proost

Hi I can repoduce the same behavior, but do you open your open file dialog
from the click event of your picturebox? If that's the case it's expected
behavior for the mouseup to fire after the open file dialog is closed.
Because you click the picturebox hence the click event gets raised but
whenever you click on the picturebox there's also a mousedown and a mouseup
to be fired and if you than handle the mouse up it's normal behavior for the
mouseup to be fired after the click event is processed even if you open an
open file dialog in the click event.

Hth

Greetz Peter
 
M

Mattbooty

No, I'm opening the open file dialog from a menu item. And it doesn't
fire the mouseup when I click the file I want then click "open" button,
only when I double click the file. I believe the open file is
interpereting a double click as a mousedown mouseup mousedown (i.e. a
single click plus another mousedown) so there is a mouseup remaining
after double clicking the file.
 
P

Peter Proost

Hi, sorry for my late reply but I had a long 4 day weekend and today is my
first day back at work but I've found something that may help you.
If you create a private variable myResult of the type DialogResult and set
it's initial value to nothing. Then if the openfiledialog returns OK set
myResult to DialogResult.OK, next in your mouseup event you can built in a
check to see if the dialogresult = OK or something else and at the end of
your mouseup event you always reset the myResult to nothing

Hth Greetz Peter

Private myResult As DialogResult = Nothing

Private Sub PictureBox1_MouseUp(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) _ Handles PictureBox1.MouseUp
If myResult <> DialogResult.OK Then
MsgBox("Mouse up")
End If
myResult = Nothing
End Sub

If objOpen.ShowDialog = DialogResult.OK Then
myResult = DialogResult.OK
PictureBox1.Image = Image.FromFile(objOpen.FileName)
End If
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top