[英]How to access the event when a list of radio button is selected at a context menu strip?
I'm creating the radio buttons in the ContextMenuStrip using the ToolStripControlHost , this way 我正在使用ToolStripControlHost在ContextMenuStrip中创建单选按钮,这种方式
RadioButton taskRb = new RadioButton();
taskRb.Text = DataGridTable.getTasks()[i].name.ToString();
taskRb.Checked = false;
ToolStripControlHost tRb = new ToolStripControlHost(taskRb);
contextMenuStrip2.Items.Add(tRb);
I need an event like CheckedChanged for the radio buttons in this list, so I can perform some actions when one of the buttons is checked. 对于此列表中的单选按钮,我需要一个诸如CheckedChanged的事件,因此当选中其中一个按钮时,我可以执行一些操作。
What is the best way to do this? 做这个的最好方式是什么? since I can't use this event with the ToolStripControlHost .
因为我不能将此事件与ToolStripControlHost一起使用 。
You can register an event handler for the CheckedChanged
event of the RadioButton
: 您可以为
RadioButton
的CheckedChanged
事件注册一个事件处理程序:
RadioButton taskRb = new RadioButton();
taskRb.CheckedChanged += new EventHandler(taskRb_CheckedChanged);
taskRb.Text = DataGridTable.getTasks()[i].name.ToString();
taskRb.Checked = false;
ToolStripControlHost tRb = new ToolStripControlHost(taskRb);
contextMenuStrip2.Items.Add(tRb);
protected void taskRb_CheckedChanged(object sender, EventArgs e)
{
// Do stuff
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.