[英]How to show different context menu strip items using radiobuttons in c#?
I have a simple windows form app consisting a button(with contextmenustrip) and two radiobuttons and there are 3 menu items namely process1 , process2 , process3 in the contextmenustrip. 我有由按钮(带的ContextMenuStrip)一个简单的Windows应用程序的形式和两个单选按钮,并有3个菜单项,即过程1, 过程2,process3中的ContextMenuStrip。
When the button is clicked while radioButton1 is enabled only process1 , process2 should show and when radioButton1 is enabled only process3 should show. 当同时radioButton1仅启用过程1单击该按钮, 进程2应显示当启用radioButton1仅process3应该显示。 How do I do this?
我该怎么做呢?
I tried to use the Available
method like below but it doesn't work 我尝试使用如下所示的
Available
方法,但是它不起作用
Button btnSender = (Button)sender;
Point ptLowerLeft = new Point(0, btnSender.Height);
ptLowerLeft = btnSender.PointToScreen(ptLowerLeft);
contextMenuStrip1.Show(ptLowerLeft);
if (radioButton1.Checked) {
process1ToolStripMenuItem.Available=true;
process2ToolStripMenuItem.Available=true;
}
if (radioButton2.Checked) {
process2ToolStripMenuItem.Available=true;
}
You have to make sure to also make the other(s) unavailable depending on the situation: 您还必须确保根据情况使其他设备不可用:
if (radioButton1.Checked)
{
toolStripMenuItem1.Available = toolStripMenuItem2.Available = true;
toolStripMenuItem3.Available = false;
}
else if (radioButton2.Checked)
{
toolStripMenuItem1.Available = toolStripMenuItem2.Available = false;
toolStripMenuItem3.Available = true;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.