我如何获得一个DoubleClick事件在.NET单选按钮? [英] How do I get a DoubleClick event in a .NET radio button?

查看:256
本文介绍了我如何获得一个DoubleClick事件在.NET单选按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够从一个标准的WinForms单选按钮赶上的DoubleClick或MouseDoubleClick事件,但他们似乎被隐藏,无法正常工作。目前,我有code是这样的:

I'd like to be able to catch the DoubleClick or MouseDoubleClick events from a standard winforms radio button, but they seem to be hidden and not working. At the moment I have code like this:

public class RadioButtonWithDoubleClick : RadioButton
{
	public RadioButtonWithDoubleClick()
		: base()
	{
		this.SetStyle( ControlStyles.StandardClick | ControlStyles.StandardDoubleClick, true );
	}

	[EditorBrowsable( EditorBrowsableState.Always ), Browsable( true )]
	public new event MouseEventHandler MouseDoubleClick;
	protected override void OnMouseDoubleClick( MouseEventArgs e )
	{
		MouseEventHandler temp = MouseDoubleClick;
		if( temp != null ) {
			temp( this, e );
		}
	}
}

有没有更简单和更清洁的方式做到这一点?

Is there a simpler and cleaner way to do it?

编辑:有关背景,我同意Raymond Chen的岗位的此处,要双击一个单选按钮的能力(如果这些都是的在对话框中只有的控制),使对话框只一点点更容易使用,谁知道这件事的人。

For background, I agree with Raymond Chen's post here that the ability to double click on a radio button (if those are the only controls on the dialog) makes the dialog just a tiny bit easier to use for people who know about it.

在Vista中使用任务对话框(见这微软指南页面或的这个MSDN网页有关具体任务对话框API )将是显​​而易见的解决方案,但我们不具备的奢侈。

In Vista using Task Dialogs (see this Microsoft guideline page or this MSDN page specifically about the Task Dialog API) would be the obvious solution, but we don't have the luxury of that.

推荐答案

根据原来的建议,我做了一个解决方案,而无需子类化使用反射radiobuton:

Based on your original suggestion I made a solution without the need to subclass the radiobuton using reflection:

MethodInfo m = typeof(RadioButton).GetMethod("SetStyle", BindingFlags.Instance | BindingFlags.NonPublic);
if (m != null)
{
    m.Invoke(radioButton1, new object[] { ControlStyles.StandardClick | ControlStyles.StandardDoubleClick, true });
}
radioButton1.MouseDoubleClick += radioButton1_MouseDoubleClick;

现在的双击事件的单选按钮被激发。 BTW:内特使用e.Clicks的建议是行不通的。在我的测试e.Clicks总是1不管我怎么快还是经常点击的单选按钮。

Now the double click event for the radiobutton is fired. BTW: The suggestion of Nate using e.Clicks doesn't work. In my tests e.Clicks was always 1 no matter how fast or often I clicked the radiobutton.

这篇关于我如何获得一个DoubleClick事件在.NET单选按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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