看板 C_Sharp 關於我們 聯絡資訊
像是 this.button1.Click += this.button2.Click; 如果我想交換兩個物件的EventHandler要怎麼換呢? 還有怎麼清掉原本設好的 Event? @@ -= 感覺不 Smart -- PTT - codejob 板,歡迎來參觀 提供發案園地,與交流討論接案經驗 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 125.230.164.184 ※ 編輯: nosrep 來自: 220.228.185.2 (01/11 13:14)
euleramon:設為null應該就清掉了吧 01/11 15:44
deduce:this.button1.Click 後面的operator只能是 += 或是 -= 01/11 16:17
deduce:否則會有compile error 01/11 16:19
deduce:-=的確不smart...不過...如果找不到更好的方法就先用吧XD 01/11 16:19
tomex:event只能在自己的class內作操作,外頭一律只能+=,-=, =null 01/11 20:56
tomex:要亙換用protect virtual,否則用delegate (講很模糊因沒作) 01/11 20:57
nosrep:Event可以設 null 嘛? 01/11 22:40
tomex:Event不能設null,它只能操作+=, -=,因為外部無法設定event 01/12 12:12
tomex:event只能由所宣告的class來觸發或設定,透過method去設null 01/12 12:16