確切地說,我必須在哪裏寫這段代碼?在哪個代碼文件中,我應該將事件處理程序分配給哪個文件以控制?
button1.MouseHover += Common_MouseHover;
問題是我想聲明一個事件處理程序並指向它的每個按鈕。這是常見的處理程序:
private void Common_MouseHover(object sender, EventArgs e)
{
Button btn = sender as Button;
if (btn != null)
btn.Image = pic
}
但我不知道我必須寫:
button1.MouseHover += Common_MouseHover;
utton2.MouseHover += Common_MouseHover;
.. etc
在設計師?究竟在哪裏?
這是的WinForms? WPF? – ryadavilli
in c#win forms – bunNyBug
我已閱讀此: http://stackoverflow.com/questions/10739572/how-make-one-event-handler-that-applies-to-multiple-controls-in-c/10739628# 10739628 並沒有理解最後一部分,我想解釋哪裏寫最後的代碼? – bunNyBug