我在ContextMenuStrip中使用ToolStripControlHost创建单选按钮
RadioButton taskRb = new RadioButton();
taskRb.Text = DataGridTable.getTasks()[i].name.ToString();
taskRb.Checked = false;
ToolStripControlHost tRb = new ToolStripControlHost(taskRb);
contextMenuStrip2.Items.Add(tRb);对于这个列表中的单选按钮,我需要一个像CheckedChanged这样的事件,所以当选中其中一个按钮时,我可以执行一些操作。
做这件事最好的方法是什么?因为我不能在ToolStripControlHost中使用这个事件。
发布于 2014-08-28 15:38:27
可以为CheckedChanged事件注册RadioButton事件处理程序。
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
}https://stackoverflow.com/questions/25551458
复制相似问题