Cancel Mouse Down

K

Kurt

I want to restrict a buttons click/doubleclick event to
firing from the left button only. How do I eliminate the
middle and right button clicks? I am able to trap these
but I'm just not sure how to cancel the event....

thx
 
A

Armin Zingler

Kurt said:
I want to restrict a buttons click/doubleclick event to
firing from the left button only. How do I eliminate the
middle and right button clicks? I am able to trap these
but I'm just not sure how to cancel the event....

You can not cancel an event, but you can ignore it.
 
K

Kurt

-----Original Message-----


You can not cancel an event, but you can ignore it.
Pardon the terminology... So how do I accomplish this?
The following allows me to trap the event. What do I
need to do to have my app ignore it?

Private Sub Flatbutton3_MouseDown(ByVal sender As Object,
ByVal e As System.Windows.Forms.MouseEventArgs) Handles
Flatbutton3.MouseDown

Dim eventString As String = Nothing
Select Case e.Button
Case MouseButtons.Right
eventString = "R"
Case MouseButtons.Middle
eventString = "M"
End Select
If eventString = "R" Or eventString = "M" Then

End If

End Sub
 
F

Fergus Cooney

Hi Kurt,

You need something along these lines:

Private MouseButtonDown As MouseButtons

Sub MouseDown()
MouseButtonDown = e.Button

Sub MouseClick() and MouseDblClick()
If MouseButtonDown <> MouseButtons.Left
Return

Sub MouseUp()
MouseButtonDown = MouseButtons.None

Regards,
Fergus
 
N

Nak

Hi Kurt,

Watch for windows messages, the following shows you how to ignore all
double clicks to a form except for the left mouse button ones. I hope this
helps.

Const WM_RBUTTONDBLCLK = &H206
Const WM_LBUTTONDBLCLK = &H203
Const WM_MBUTTONDBLCLK = &H209

Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
Select Case m.Msg
Case WM_RBUTTONDBLCLK, WM_MBUTTONDBLCLK : Return
Case Else
Call MyBase.WndProc(m)
End Select
End Sub

Private Sub Form1_DoubleClick(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.DoubleClick
MessageBox.Show("DOUBLE CLICK!")
End Sub

To implement this into a control of your own you just need to override
the WndProc procedure.

Nick.

--
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
"No matter. Whatever the outcome, you are changed."

Fergus - September 5th 2003
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
 
A

Armin Zingler

Kurt said:
Pardon the terminology... So how do I accomplish this?
The following allows me to trap the event. What do I
need to do to have my app ignore it?

Private Sub Flatbutton3_MouseDown(ByVal sender As Object,
ByVal e As System.Windows.Forms.MouseEventArgs) Handles
Flatbutton3.MouseDown

Dim eventString As String = Nothing
Select Case e.Button
Case MouseButtons.Right
eventString = "R"
Case MouseButtons.Middle
eventString = "M"
End Select
If eventString = "R" Or eventString = "M" Then

End If

End Sub


Sorry, I don't understand. If you delete the code, you are ignoring the
event.
 
F

Fergus Cooney

Hi Armin,

Kurt doesn't want to ignore MouseDown for Mid and Right buttons, he wants
to ignore Click and DblClick. These don't provide the button information which
must therefore be obtained in MouseDown, used in Click and cleared in MouseUp.

Regards,
Fergus
 
N

Nak

Kurt doesn't want to ignore MouseDown for Mid and Right buttons, he
wants
to ignore Click and DblClick. These don't provide the button information which
must therefore be obtained in MouseDown, used in Click and cleared in
MouseUp.

Hi Fergus,

Look at my solution :)

Nick.

--
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
"No matter. Whatever the outcome, you are changed."

Fergus - September 5th 2003
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
 
A

Armin Zingler

Fergus Cooney said:
Kurt doesn't want to ignore MouseDown for Mid and Right buttons,
he wants
to ignore Click and DblClick. These don't provide the button
information which must therefore be obtained in MouseDown, used in
Click and cleared in MouseUp.

Aaaaahhh... now I got it! :) He wants to distinguish between different
mouse buttons in the click event - ok.
 
N

Nak

Hmm, maybe I'm imagining things, but I did provide the solution, didn't I?
It prevents all double clicks except the left double click from being
raised, as requested, oh well :p

Nick.

--
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
"No matter. Whatever the outcome, you are changed."

Fergus - September 5th 2003
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
 
F

Fergus Cooney

Hi Nick,

Sorry, mate, I got caught up in all sorts. Yes I tested it (couple of
syntaxes, no worries) and it works a dream. :) The only downside for me is
the having to hunt around for WM_THISANDTHAT as these don't stay in my brain
(lack of use*).

I've used my technique ever since I found that VB doesn't provide mouse
button info in Click and DblClick. And access to WndProc (what's that) wasn't
available then.

So now the question is - go with trapping multiple events and passing
global mouse button info around (a portable approach) or keep it centralised
in WndProc (an API approach). Decisions, decisions. :)

I wonder if Kurt will tell us which one takes his fancy?

Regards,
Fergus

* The constants, not the brain :)
 
N

Nak

Hi Fergus,
Sorry, mate, I got caught up in all sorts. Yes I tested it (couple of
syntaxes, no worries) and it works a dream. :) The only downside for me is
the having to hunt around for WM_THISANDTHAT as these don't stay in my brain
(lack of use*).

I see what you mean. Have you tried downloading an API viewer? They come
in quite handy sometimes

http://www.activevb.de/rubriken/apiviewer/index-apiviewereng.html

This one is quite compact, and contains all constanst etc..

Nick.

--
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
"No matter. Whatever the outcome, you are changed."

Fergus - September 5th 2003
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
 
F

Fergus Cooney

Hi Nick,

I actually downloaded that very one a few weeks back but it won't work for
me. It gives me the language dialogue and then exits when I choose English
(the only option). I've emailed the guy (Christoph) but his suggestion
(regsvr) didn't work out either. :-(

Christoph mentioned having to install it with the VB6 plug-in but I'm not
sure what he means. Do you run it within VB6 or standalone?

Any ideas?

Regards,
Fergus
 
F

Fergus Cooney

Hi Nick,

I actually downloaded that very one a few weeks back but it won't work for
me. It gives me the language dialogue and then exits when I choose English
(the only option). I've emailed the guy (Christoph) but his suggestion
(regsvr) didn't work out either. :-(

Christoph mentioned having to install it with the VB6 plug-in but I'm not
sure what he means. Do you run it within VB6 or standalone?

Any ideas?

Regards,
Fergus

ps. This is a resend. The wierdest thing happened. I sent this about four
minutes ago. Then went to Inbox and back to the group to force OE to load and
show. There was my message and as soon as I clicked it to make it unhighlight,
it got struck out and the message "deleted from the server came up". Is VB6 a
swear word or something?
 
F

Fergus Cooney

Hi Nick,

I actually downloaded that very one a few weeks back but it won't work for
me. It gives me the language dialogue and then exits when I choose English
(the only option). I emailed the guy (Christoph) but his suggestion (regsvr)
didn't work out either. :-(

Christoph mentioned having to install it with the VB6 plug-in but I'm not
sure what he means. Do you run it within VB6 or standalone?

Any ideas?

Regards,
Fergus

ps. This is a resend. The wierdest thing happened. I sent this about four
minutes ago. Then went to Inbox and back to the group to force OE to load and
show. There was my message and as soon as I clicked it to make it unhighlight,
it got struck out and the message "deleted from the server came up". Is VB6 a
swear word or something?

pps. This is the second resend. It happened again so I'm trying a bit further
to the left.
 
N

Nak

Hi Fergus,
Christoph mentioned having to install it with the VB6 plug-in but I'm not
sure what he means. Do you run it within VB6 or standalone?

I thought the plug-ins were so that you could use it directly in the IDE
first of all. But after closer inspection I believe them to be just for
copying the declarations, constants etc. into the clipboard for your desired
syntax.

I installed it with all plug-ins installed in the end, even though I only
use VB.NET. I remember having installation problems to start with too
actually, I couldn't actually get the application to appear after launching
it, so I uninstalled and installed again, and when the first selection
appeared I selected VB6 (or whatever it was, I cant quite remember).

The viewer is quite good, with the exception that you cannot search for
constants by their value, nor does it have descriptions and examples on the
API's, like the one at www.allapi.net.

Nick.

--
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
"No matter. Whatever the outcome, you are changed."

Fergus - September 5th 2003
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
 
N

Nak

pps. This is the second resend. It happened again so I'm trying a bit
further
to the left.

LOL think Outlook is being it's usual unreliable self :)

Nick.

--
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
"No matter. Whatever the outcome, you are changed."

Fergus - September 5th 2003
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
 
H

Herfried K. Wagner [MVP]

Hello,

Nak said:
I see what you mean. Have you tried downloading an API viewer?
They come in quite handy sometimes

http://www.activevb.de/rubriken/apiviewer/index-apiviewereng.html

This one is quite compact, and contains all constanst etc..

Yep... Nevertheless the .NET support is really poor and most of the
declares etc. must be corrected by hand. If I have more time I will talk
with Christoph (a "coworker" at ActiveVB) about that.
 
F

Fergus Cooney

Hi Herfried,

|| Nevertheless the .NET support is really poor ...
|| If I have more time I will talk with Christoph ...

Christoph said to me that if <he> had the time he'd do something about it,
or maybe someone else could?

I think he's too busy reading Terry Pratchett. ;-)

Regards,
Fergus
 
N

Nak

I think he's too busy reading Terry Pratchett. ;-)

LOL

Do you read Fergus?

Nick.

--
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
"No matter. Whatever the outcome, you are changed."

Fergus - September 5th 2003
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
 

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

Similar Threads


Top