本文介绍了按钮双击事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用按钮的实际双击事件

i不能使用鼠标按下事件和e.clicks = 2进行双击,因为我有一些代码需要执行鼠标up事件已找到一个链接按钮双击



[]



这里声明ControlStyles.StandardDoubleClick对于按钮设置为false所以有没有办法将其设置为true并使用doubleclick事件或任何其他方式进行按钮双击



我尝试过:



Private Sub Button_Click(ByVal sender As System.Object,ByVal e As MouseEventArgs)



如果e.Clicks = 2那么

MsgBox(e.Clicks.ToString)

结束如果

end sub

i want to use actual double click event for buttons
i cant use mouse down event and e.clicks =2 for double click because i have some code on mouse up event which needed to be executed i have found one link for button double click

Button.DoubleClick Event (System.Windows.Forms)[^]

here it states that ControlStyles.StandardDoubleClick are set to false for button so is there any way to set it true and use doubleclick event or any other way for button double click

What I have tried:

Private Sub Button_Click(ByVal sender As System.Object, ByVal e As MouseEventArgs)

If e.Clicks = 2 Then
MsgBox(e.Clicks.ToString)
end if
end sub

推荐答案

public class MyButton : Button
    {
    public MyButton()
        {
        SetStyle(ControlStyles.StandardClick | ControlStyles.StandardDoubleClick, true);
        }
    }

你必须启用这两种样式才能双击工作。

然后你可以添加按钮,并手动添加事件处理程序:

You must enable both styles for double click to work.
Then you can add the button, and manually add the event handler:

MyButton mb = new MyButton();
mb.Text = "My Button";
mb.Size = new Size(100, 30);
mb.Location = new Point(100, 100);
mb.Visible = true;
Controls.Add(mb);
mb.DoubleClick += MyButton_DoubleClick;

您无法通过设计器中的属性窗格添加处理程序,因为它是一个隐藏事件。

You can't add the handler via the Properties pane in the designer, as it's a hidden event.


这篇关于按钮双击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 16:42