|
我new 了一個NotifyIcon 對象,在通知區(qū)域顯示,當(dāng)單擊時候需要觸發(fā)一個帶參數(shù)的事件,//butSuspendAll是Form1中的一個按鈕,dgvSoft是Form1中的DataGridView
private void butSuspendAll_Click(object sender, EventArgs e){
obj.DoubleClick += new EventHandler(aa_Click(sender,e,i);//這里加入?yún)?shù)就會報錯
}
private void aa_Click(object sender, EventArgs e,int i)
{
Process p = new Process();
p.StartInfo.FileName = @dgvSoft.Rows[i].Cells[6].Value.ToString();
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;p.Start();
}
-----------------------實在不好意思,我的積分都被前段時間抽獎花光了,就剩下9個了,如果采納您的答案,也只有這么多給了。
采納率:48%
10級
2013.03.24
obj.DoubleClick += new EventHandler(aa_Click(sender,e,i);//這里加入?yún)?shù)就會報錯
這里你要注冊NotifyIcon 對象的雙擊事件, new EventHandler(aa_Click); 這里只能傳方法名,不能傳參數(shù)進(jìn)去。
還有EventHandler只支持兩個參數(shù)(object sender, EventArgs e)
所以
private void aa_Click(object sender, EventArgs e,int i)
{
Process p = new Process();
p.StartInfo.FileName = @dgvSoft.Rows[i].Cells[6].Value.ToString();
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;p.Start();
}
這個方法的,int i參數(shù)必須去掉。
其實我想到個方法,你不需要傳這個參數(shù)的
你可以把這個參數(shù)保存到NotifyIcon 對象的Tag中
觸發(fā) aa_Click事件時,你可以從 NotifyIcon a =(NotifyIcon )sender;
int i = Convert.ToInt32(a.Tag);
這樣一樣可以取到的,有疑問繼續(xù)問我! |
|
|