简体   繁体   English

在上下文菜单栏中选择单选按钮列表时,如何访问事件?

[英]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 我正在使用ToolStripControlHostContextMenuStrip中创建单选按钮,这种方式

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 : 您可以为RadioButtonCheckedChanged事件注册一个事件处理程序:

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.

相关问题 如何为上下文菜单单击事件获取选定的列表视图项 - How to get selected list view item for context menu click event 使用上下文菜单栏在运行时创建自定义控件列表项目单击事件 - creating a List of Custom Controls at run-time using the context menu strip Item Click Event 上下文菜单删除所选按钮 - context menu to delete selected button 如何正确刷新上下文菜单条 - How to properly refresh Context menu strip 如何检查鼠标是否在上下文菜单栏上 - How to check if mouse is on the context menu strip 为什么我的单选按钮列表仅在所选值= 1时触发 - Why my radio button list fires only when the selected value = 1 选择单选按钮列表项后如何从gridview获取单元格值? - How to get cell value from gridview when radio button list item is selected? 如何使用jQuery获取或设置单选按钮列表的选定索引? - How to get or set Selected index of the Radio Button List using jquery? 如何选中单选按钮以及如何仅控制在列表视图中选择的一个单选按钮 - How to get checked radio button and how to control only one radio button selected in list view 在以编程方式填充后单击时,如何获取上下文菜单条中项目的文本? - How can i get the text of an item in context menu strip when clicked after populated programmatically?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM