简体   繁体   English

如何从工具条单击事件中调用Menustrip项目

[英]How to call Menustrip items from toolstrip click event

this is my code and from toolstrip click event i want to call the menustrip sub items Ex: Menu like : Settings -> User. 这是我的代码,并且从toolstrip单击事件中,我想调用menustrip子项,例如:Menu::Settings-> User。 I want to call user_click event from toolstip click 我想从工具提示点击中调用user_click事件

private void tbrIUC1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
{
    string menuname="mnuuser";
    e.ClickedItem.Click += new EventHandler(menuname + "_Click");
}

You can use anonymous delegate: 您可以使用匿名委托:

private void tbrIUC1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
{
    string menuname="mnuuser";
    e.ClickedItem.Click += (s, ev) => { your code when clicked };
}

From another stackoverflow post I got the following working for me: 从另一个stackoverflow帖子中,我得到了以下工作:

ButtonName.Click += (se, ev) => button1_Click(se, ev);

Link to "inspiration" How can I create a dynamic button click event on a dynamic button? 链接到“灵感” 如何在动态按钮上创建动态按钮单击事件? Look for the answer from A9S6 and the comment to this from Scott Beeson 寻找A9S6的答案以及Scott Beeson对此的评论

EDIT 编辑

To call a function BASED on the function name (string) I got the following article: http://www.vcskicks.com/call-function.php I haven't got it working for me by now but I wanted to share a possible solution 要基于函数名称(字符串)调用函数,我收到了以下文章: http : //www.vcskicks.com/call-function.php到目前为止,我还没有使用它,但是我想分享一个可能的解决方案

If all fails: I recommend declaring a new method with a Switch that gets the control and the string passed 如果全部失败:我建议使用Switch声明一个新方法,该方法获取控件和传递的字符串

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM