button.click和label.click之间的行为差​​异 [英] Difference in the behaviour between button.click and label.click

查看:68
本文介绍了button.click和label.click之间的行为差​​异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现这两个控件的Click-Event之间的行为存在差异。

Button-Control的Click-Event(或OnClick方法)提高了2倍来自Label-Control(或Control)的相同事件(方法)。



任何人都可以解释为什么 - 或者更好地做什么来实现两个控件的反应以同样的方式?







好的......有人可以随意投票给我提问(也许这很容易被问到)......但没有人能给出答案......非常好...



我尝试了什么:



目前不知道... :( ..

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 ... :( ..

推荐答案

参考0x01AA和Alan N的评论和我自己的研究,我发现这是解决方法来创建一个自己定制的Button,它继承了Control或ButtonBase或Label:



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 :

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)





正如Alan N写的那样评论,我想检测延迟来自检测时间,检测是否也可以成为一个DoubleClick。



感谢所有人纪念nts引导我进入目标...



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 ...


在咨询了c#参考源并比较了Button和Control-特别是ctors之后 - 我发现这完成了这项工作:



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

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



我希望它有所帮助。


I hope it helps.


这篇关于button.click和label.click之间的行为差​​异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆