新手请教:使用单选按钮时,CheckedChanged事件如何激发
学习编程时,在窗体上放了以下6个单选按钮,设置了变量buttonType,不知哪个地方没有设置正确,点击displayButton按钮时没有出现预期效果,说明单选按钮的CheckedChanged事件没有调用,请教各位!private MessageBoxButtons buttonType = MessageBoxButtons.RetryCancel;
private void buttonType_CheckedChanged(object sender, EventArgs e)
{
if (sender == ok)
buttonType = MessageBoxButtons.OK;
else if (sender == okCancel)
buttonType = MessageBoxButtons.OKCancel;
else if (sender == abortRetryIgnore)
buttonType = MessageBoxButtons.AbortRetryIgnore;
else if (sender == yesNoCancel)
buttonType = MessageBoxButtons.YesNoCancel;
else if (sender == yesNo)
buttonType = MessageBoxButtons.YesNo;
else
buttonType = MessageBoxButtons.RetryCancel;
}
private void displayButton_Click(object sender, EventArgs e)
{
DialogResult result = MessageBox.Show("this is your custom messagebox", "custom messagebox", buttonType, MessageBoxIcon.Question, 0, 0);
switch (result)
{
case DialogResult.OK:
displayLabel.Text = "ok was pressed";
break;
case DialogResult.Cancel:
displayLabel.Text = "cancel was pressed";
break;
case DialogResult.Abort:
displayLabel.Text = "Abort was pressed";
break;
case DialogResult.Retry:
displayLabel.Text = "Retry was pressed";
break;
case DialogResult.Ignore:
displayLabel.Text = "Ignore was pressed";
break;
case DialogResult.Yes:
displayLabel.Text = "Yes was pressed";
break;
case DialogResult.No:
displayLabel.Text = "No was pressed";
break;
}
}