Click here to Skip to main content
15,884,472 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
I found a difference in the Behaviour between the Click-Event from those both controls.
The Click-Event (or the OnClick-method) from the Button-Control is raised abot 2 times faster than the same Event (method) from the Label-Control (or Control).

Could anyone explain me why - or better what to do to achieve that both controls react in the same way ?



OK ... someone felt free to vote my question down (perhaps it is to simple to be asked) ... but no one is able to give an answer ... very good ...

What I have tried:

no idea in the moment ... :( ..
Posted
Updated 21-Aug-16 21:20pm
v2
Comments
OriginalGriff 21-Aug-16 7:19am    
How are you testing it?
What kind of numbers are you getting?
Ralf Meier 21-Aug-16 8:58am    
I found it out by coincidence.
I have self-created Button-Control, which derives from (Windows.Forms.)Control (I also tested the same with the deriving from Label or ButtonBase).
In my Application I work with the Events. Now I have a purpose which could have fast Button-pressings. Here my Button allows only severall Clicks. If I change the Inheritance (from my Control) to Button I could work with it like I want.
So ... from here comes my question. Nothing (in the code) changed except the Inheritance - but the Performance changes a lot ...
Karthik_Mahalingam 21-Aug-16 7:21am    
Post your code
Ralf Meier 21-Aug-16 8:59am    
see my reply to the comment from OG ...
Karthik_Mahalingam 21-Aug-16 11:54am    
ok

After consulting the c# reference source and comparing Button and Control- especally ctors - I found that this does the job:

C#
public class MyLabel : Label
{
    public MyLabel()
    {
        SetStyle(ControlStyles.StandardDoubleClick, false);
    }
}

I hope it helps.
 
Share this answer
 
Comments
Ralf Meier 22-Aug-16 3:35am    
Very good and thank you very much. This Solution is much better (and also much easier) than my own.
+5 !!!!
[no name] 22-Aug-16 3:41am    
You are welcome. Thank you for your vote.
Maciej Los 22-Aug-16 4:11am    
5ed!
[no name] 22-Aug-16 4:21am    
Thank you very much Maciej.
Referring to the comments of 0x01AA and Alan N and my own researches I found this as "work-around" to create an own customized Button which inherits Control or ButtonBase or Label :

VB
Private fm_Click As Boolean = False

Protected Overrides Sub OnMouseDown(e As System.Windows.Forms.MouseEventArgs)
   If Not fm_Click Then
        RaiseEvent MouseClick(Me, e)
        fm_Click = True
    End If
     MyBase.OnMouseDown(e)
End Sub

Protected Overrides Sub OnMouseUp(e As System.Windows.Forms.MouseEventArgs)
    fm_Click = False
    MyBase.OnMouseUp(e)
End Sub

Public Shadows Event MouseClick(ByVal sender As Object, e As System.Windows.Forms.MouseEventArgs)


As Alan N has written in his comment, I suppose that the detect "delay" comes from the detection time which is needed to detect if an incomming Click could also be a DoubleClick.

Thanks to all for the comments which guided me to the goal ...
 
Share this answer
 
v2
Comments
Maciej Los 22-Aug-16 2:58am    
5!
Ralf Meier 22-Aug-16 3:36am    
Thank you Maciej.
But take also a look to the Solution from 0x01AA ...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900