473,785 Members | 2,209 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Click vs DoubleClick

I have a control that need to perform one behavior when it's Clicked and a different behavior when it's DoubleClicked.

It seems that you can't get a DoubleClick without first getting a Click. So what's the best way to keep from executing the click functionality before it's determined if it's a double click or not?

Or do I just have to "undo" the Click stuff everytime a DoubleClick is received?

Thanks.

J
Apr 22 '07 #1
3 12302
On Sat, 21 Apr 2007 17:24:25 -0700, <rl*****@newsgr oups.nospamwrot e:
I have a control that need to perform one behavior when it's Clicked and
a different behavior when it's DoubleClicked.

It seems that you can't get a DoubleClick without first getting a
Click. So what's the best way to keep from executing the click
functionality before it's determined if it's a double click or not?

Or do I just have to "undo" the Click stuff everytime a DoubleClick is
received?
Yup, that's a tricky one. :) It does come up now and then, and generally
speaking the correct UI behavior is to always do the click action, and
then the double-click action if the double-click also happens.

This, of course, means that you need to define your UI so that whenever
the user is double-clicking, a single-click always makes sense. This is
*almost always* the right thing to do, but exceptions do occur. When they
do, you can either do what you propose (undo the single-click action if
you get the double-click) or you can wait out the double-click time to see
if a second click comes along, and if it doesn't then you do the
single-click action instead. The latter is what other applications
generally do.

As you can see, it's a lot easier if you can design your user-interface so
that always doing the single-click action makes sense. :)

Pete
Apr 22 '07 #2
Hi J,

The reason why the Click event is always raised before the DoubleClick
event of a control when the user double clicks on the control is that the
system always sends a WM_LBUTTONDOWN message to the control before sends a
WM_LBUTTONDBLCL K message.

Once the control receives the WM_LBUTTONDOWN message, the Click event of
the control is raised.

If you don't like to get the Click event fired before the DoubleClick event
is raised, I think a possible way is to hold the WM_LBUTTONDOWN message for
a short time when the control receives the this message. If the control
doesn't receive the WM_LBUTTONDBLCL K message during this short time, then
send this message out; otherwise, don't send.

The following is a sample.

using System.Runtime. InteropServices ;
class MyControl : Control
{
int WM_LBUTTONDOWN = 0x0201;
int WM_LBUTTONDBLCL K = 0x0203;

Message clickMessage;
System.Windows. Forms.Timer clickTimer = new
System.Windows. Forms.Timer();
bool clickflag = false;

[DllImport("user 32.dll")]
public static extern int SendMessage(Int Ptr hWnd,int msg, IntPtr
wParam, IntPtr lParam);

public MyControl()
{
clickTimer.Inte rval = 100;
clickTimer.Tick += new EventHandler(cl ickTimer_Tick);
}

void clickTimer_Tick (object sender, EventArgs e)
{
this.clickTimer .Stop();
clickflag = true;
SendMessage(thi s.Handle, clickMessage.Ms g, clickMessage.WP aram,
clickMessage.LP aram);
}
protected override void WndProc(ref Message m)
{
if (m.Msg == WM_LBUTTONDOWN)
{
if (clickflag == false)
{
clickMessage = m;
clickTimer.Star t();
}
else
{
clickflag = false;
base.WndProc(re f m);
}
}
else if (m.Msg == WM_LBUTTONDBLCL K)
{
clickTimer.Stop ();
base.WndProc(re f m);
}
else
{
base.WndProc(re f m);
}
}
}

Hope this helps.
If you have any question, please feel free to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support

=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no rights.

Apr 23 '07 #3
Thanks for the responses... In reviewing the interface, I considered both methods and chose option 3...

I changed the code so that one action is tied to aleft click and the other to a right click. Kinda like the old windows MineSweper game. That suits this app pretty well, anyway.

Thanks.

Jerry
<rl*****@newsgr oups.nospamwrot e in message news:up******** *****@TK2MSFTNG P06.phx.gbl...
I have a control that need to perform one behavior when it's Clicked and a different behavior when it's DoubleClicked.

It seems that you can't get a DoubleClick without first getting a Click. So what's the best way to keep from executing the click functionality before it's determined if it's a double click or not?

Or do I just have to "undo" the Click stuff everytime a DoubleClick is received?

Thanks.

J
Apr 25 '07 #4

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

Similar topics

2
513
by: Rob Mayo | last post by:
OK, maybe this is my opinion, maybe these are bugs. Given the folowing: I have a NotifyIcon on my Form, a Context menu associated with the NotifyIcon, and a MenuItem on the ContextMenu set as default. When the default MenuItem is clicked, there is code to no longer show the NotifyIcon. What I feel should happen is when I double-click the NotifyIcon in the system tray, it should perform the default menu item's Click event.
11
535
by: Thom Little | last post by:
I would like three states on an icon ... Left Click Right Click Double Click Left Click is fired at least once on a Double Click Is there a good example that shows how to determine if the user entered a Left Click or a Double Click?
6
8642
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 Sub Button1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button1.MouseUp If e.Clicks = 1 Then
0
1355
by: Lloyd Sheen | last post by:
I am trying to do two things from a listview. First is on a double click to perform an action on the object which was double clicked. FullRowSelect is set to true for the Listview. Code for the doubleClick event is: Private Sub SongList_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles SongList.DoubleClick If SongList.SelectedItems.Count = 0 Then Exit Sub
3
2958
by: Siv | last post by:
Hi, I have a ListView control in a Windows application, currently single clicking a customer name in this list, selects the customer and displays their details in text boxes to the right of the list. The user must then click a button to select that customer and move off the page to the main database details. I would like to implement being able to double-click the listview item and it have the same effect as single clicking and then...
2
3373
by: Boni | last post by:
Dear all, I am interested in mouse down and double click events of a control. When doubleclick happens the processing for mouse down should't be done I did follwing: sub MyMouseDown(.) handles MouseDown(..) if e.clicks>1 then return 'This is double click <-----------------(*) .... end sub sub DoubleClick(.) handles DoubleClick(..) end sub
9
8059
by: Armando | last post by:
I have an app (A2000) where I am letting the user move an object on the screen. I use the OnClick for a command button event to modify the object's Top (or Left) properties, but you can only click slowly. That is, every other click is ignored, because Access is seeing a double click event. I would put the same code there, except I'm also using the SHIFT key (during mouse click) to cause bigger moves, and there's no SHIFT flag for the...
1
4119
by: Marcel Brekelmans | last post by:
Hello, I have implemented a NotiFyIcon and am using both DoubleClick and Click events. But the Doubleclick action on my icon also fires the Click event. Am I missing some setting somewhere or is this normal behavior? I can't find anything about it in the official documentation. Thanks
0
1024
by: Marc | last post by:
OK, last post of the day I promise! I have a doubleclick event below that is not working. The strange this is that the single 'click' event works fine? I did notice that doubleclick does not appear as an event option for this button, but i get no validation errors if i typr doubleclick.
0
10346
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10096
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
9956
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8982
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7504
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6742
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5514
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4055
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
2
3658
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.