使用它正在取得可重複使用一個單獨的類,需要通過它這會從上下文菜單中單擊事件中調用函數...傳遞一個方法的類事件處理器
問題:功能AREN輸入EventHandlers ....也是不同的EventHandler需要不同的參數在...例如的OnClose的退出按鈕....
編輯:
在類X
public void AddMenuItem(String name, EventHandler target)
{
MenuItem newItem = new MenuItem();
newItem.Index = _menuItemIndex++;
newItem.Text = name;
newItem.Click += target;
_contextMenu.MenuItems.Add(newItem);
}
在WPF:
addToTray.AddMenuItem("&Exit", Exit);
我喜歡它,鏈接到的下面的方法,但在這一點上任何方法都可以。
private void ShouldIExit(object sender, System.ComponentModel.CancelEventArgs e)
{
// checks if the Job is running and if so prompts to continue
if (_screenCaptureSession.Running())
{
MessageBoxResult result = System.Windows.MessageBox.Show("Capturing in Progress. Are You Sure You Want To Quit?", "Capturing", MessageBoxButton.YesNo);
if (result == MessageBoxResult.No)
{
e.Cancel = true;
return;
}
}
_screenCaptureSession.Stop();
_screenCaptureSession.Dispose();
}
這聽起來像你會創建一個調試噩夢 – Beth 2011-03-21 20:08:44
@Beth - 我半睡半醒,這樣做是非常非常。 – 2011-03-21 20:22:31