473,513 Members | 3,621 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to caputre Mouse single and Double click evennts

Hi All,

How to capture Mouse Single click and mouse double click event on Commnad
Button.
I am doing as follows.

Private Sub Button1_MouseUp(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles Button1.MouseUp

If e.Clicks = 1 Then

MsgBox("1")

Else

MsgBox("2")

End If

End Sub
But each time I gets single click.
Even after clicking mouse button twice, events gets fired on first click and
I am not been able to capture double click event.

Any suggestions will be appreciated.

Thanks in advance
Sakharam Phapale



Nov 21 '05 #1
6 8610
"Sakharam Phapale" <sp******@annetsite.com> wrote in
news:#V**************@TK2MSFTNGP12.phx.gbl:
Hi All,

How to capture Mouse Single click and mouse double click event on
Commnad Button.
I am doing as follows.

Private Sub Button1_MouseUp(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles Button1.MouseUp

If e.Clicks = 1 Then

MsgBox("1")

Else

MsgBox("2")

End If

End Sub
But each time I gets single click.
Even after clicking mouse button twice, events gets fired on first
click and I am not been able to capture double click event.

Any suggestions will be appreciated.

Thanks in advance
Sakharam Phapale


Don't use button.mouseup, there are existing events for this:
button.click
button.doubleclick

Nov 21 '05 #2
"Sakharam Phapale" <sp******@annetsite.com> schrieb:
How to capture Mouse Single click and mouse double click event on Commnad
Button.


How should Windows know at time n that the user will make a click at time n
+ 1? This problem can be solved, although the solution might irritate the
user because single clicks will be processed with a lag. You can do that by
storing the time when the first click occured and then check the time
differene between the first and the 2nd click.
'SystemInformation.DoubleClickTime' will give you the system's double click
time. If it's possible I would try to avoid to assign different operations
to a control's 'Click' and 'DoubleClick' events.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #3
Use Button1_Click and Button1_DoubleClick events procedures

"Sakharam Phapale" <sp******@annetsite.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Hi All,

How to capture Mouse Single click and mouse double click event on Commnad
Button.
I am doing as follows.

Private Sub Button1_MouseUp(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles Button1.MouseUp

If e.Clicks = 1 Then

MsgBox("1")

Else

MsgBox("2")

End If

End Sub
But each time I gets single click.
Even after clicking mouse button twice, events gets fired on first click
and
I am not been able to capture double click event.

Any suggestions will be appreciated.

Thanks in advance
Sakharam Phapale


Nov 21 '05 #4
"whoopding" <vb@whoopding.com> schrieb:
Use Button1_Click and Button1_DoubleClick events procedures


Still, for every 'DoubleClick' event a 'Click' event is fired too.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #5
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in
news:eo**************@TK2MSFTNGP12.phx.gbl:
"whoopding" <vb@whoopding.com> schrieb:
Use Button1_Click and Button1_DoubleClick events procedures


Still, for every 'DoubleClick' event a 'Click' event is fired too.


hmm doubleclick never fires anyway:

"This member supports the .NET Framework infrastructure and is not intended
to be used directly from your code."

Nov 21 '05 #6
jo0ls <sp**@example.invalid> wrote in news:EvLOd.11291$8B3.8157
@text.news.blueyonder.co.uk:
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in
news:eo**************@TK2MSFTNGP12.phx.gbl:
"whoopding" <vb@whoopding.com> schrieb:
Use Button1_Click and Button1_DoubleClick events procedures
Still, for every 'DoubleClick' event a 'Click' event is fired too.


hmm doubleclick never fires anyway:

"This member supports the .NET Framework infrastructure and is not

intended to be used directly from your code."


so a custom button to capture clicks:

Private Class dblClickButton
Inherits System.Windows.Forms.Button
Public noOfClicks As Integer = 0
Public ReadOnly Property [Clicks]() As Integer
Get
Return noOfClicks
End Get
End Property

Protected Overrides Sub WndProc(ByRef m As Message)
If m.Msg = &H201 Then noOfClicks = 1
If m.Msg = &H203 Then noOfClicks = 2
MyBase.WndProc(m)
End Sub
End Class

Those hex values used to be listed in the winuser.h file in the sdk but
have dissapeared.
&H201 occurs when it's a single click
&H203 occurs when it's a double clik
we still want them processed so feed them back with mybase.wndproc(m)

With the new base button you can catch the single and double clicks:

Dim WithEvents btn1 As New dblClickButton

Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
btn1.Location = New System.Drawing.Point(150, 100)
Me.Controls.Add(btn1)
btn1.Text = "click me"

End Sub
Private Sub btn1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btn1.Click
Me.Label1.Text = Me.btn1.Clicks
End Sub
BUT, it will still catch a single click just before each double click
fires, but at least it does know if a double click occured.
Nov 21 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
937
by: Harry J. Smith | last post by:
How can you detect a mouse double click on a text box? I tried the following but it does not work. private void richTextOut_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e) // Process Mouse up in output TextBox {
1
14659
by: Sakharam Phapale | last post by:
Hi All, How to capture Mouse Single click and mouse double click event on Commnad Button. I am doing as follows. Private void Button1_MouseUp(Object sender, System.Windows.Forms.MouseEventArgs e) {
5
4713
by: Nick | last post by:
Hey guys, I have 2 events on a windows forms datagrid, the mouse move as well as the double click events. What's happening is that when I double click on a row in the grid, the mouse move event gets triggered and the double click is not identified at all. Is there any way I can invoke the double click when the mouse move also exists?
1
5286
by: scott_gui | last post by:
Creating a Windows application: <Double-Button-1> mouse event has a conflict when there is also a binding to the <Button-1> event. It seems like a silly oversight that performing a double click will also initiate the single click action. Has anyone figured out a way to circumvent this problem? Right now I am making the Double click function...
2
4376
by: scott_gui | last post by:
I am creating a Windows application: The mouse event <Double-Button-1> has a conflict when the <Button-1> event also has a binding. Double clicks will first perform the single click action. This seems a little silly. Anyone know how to circumvent this? Right now I am having the function that is bound to the double click event undo the...
0
1415
by: mmcd79 | last post by:
I'm wondering if anyone else is having this issue. It's driving me batty. It seems my mouse wants to "double click" on items when I'm just doing a single click. I thought it was the mouse so I swapped it out for another. Same thing happening with the new mouse. As I would highlight controls on a form in order to get the properties...
0
7269
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7394
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7559
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7123
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7542
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5701
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3248
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3237
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1611
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.