我希望能夠從標準的winforms單選按鈕捕捉DoubleClick或MouseDoubleClick事件,但它們似乎隱藏起來並不起作用。目前我有這樣的代碼:如何在.NET單選按鈕中獲得DoubleClick事件?
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);
}
}
}
是否有一個更簡單和更乾淨的方法來做到這一點?
編輯:有關背景,我同意Raymond Chen的崗位here,要雙擊一個單選按鈕(如果這些是僅對話框上的控件)的能力,使對話只是一點點更容易使用瞭解它的人。
在Vista中使用任務對話框(請參閱this Microsoft guideline page或this MSDN page specifically about the Task Dialog API)將是顯而易見的解決方案,但我們沒有那麼奢侈。
我接受這一個,因爲儘管我認爲我自己的解決方案對於我的案例來說更簡單,我將多次使用相同的控件,如果有人只需要一兩個,那麼您的要簡單得多。 – Ant 2009-07-03 14:10:23
由於Clicks == 2從來沒有發生過,所以這看起來似乎沒有用於.NET 3.5。 – Wernight 2011-03-08 15:09:46