我得由我所有的單選按鈕共享一個事件處理程序:爲什麼我的共享事件處理程序認爲處理程序的主格「owner」始終是發件人?
private void radioButtonPackers_CheckedChanged(object sender, EventArgs e)
{
var rb = sender as RadioButton;
if (rb == radioButtonPackers)
{
team = NFCNorth.Packers;
} else if (rb == radioButtonBears)
{
team = NFCNorth.Bears;
} else if . . .
}
RB總是被看作是radioButtonPackers,我檢查了radioButtonBears,radioButtonVikings,或radioButtonLions單選按鈕後還是一樣。
我必須做這樣的事情:
if (radioButtonPackers.Checked)
{
team = NFCNorth.Packers;
}
else if (radioButtonBears.Checked)
{
team = NFCNorth.Bears;
}
. . .
?
如何一定是你該事件處理程序是真的* *在所有按鈕之間共享?你能展示一個簡短但完整的程序來證明問題嗎? –
從Designer.cs文件中: this.radioButtonPackers.CheckedChanged + = new System.EventHandler(this.radioButtonPackers_CheckedChanged); this.radioButtonBears.CheckedChanged + = new System.EventHandler(this.radioButtonPackers_CheckedChanged); this.radioButtonLions.CheckedChanged + = new System.EventHandler(this.radioButtonPackers_CheckedChanged); this.radioButtonVikings.CheckedChanged + = new System.EventHandler(this.radioButtonPackers_CheckedChanged); –