如何在运行时选择菜单项? [英] How to select a menu item at runtime?

查看:69
本文介绍了如何在运行时选择菜单项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我在点击事件中有这个代码:



 MenuItem myItem =  new  MenuItem(  Tab,TabIndex); 
Menu1.Items.AddAt(TabIndex,myItem);
myItem.Selected = true ;





现在举个例子我点击这个点击事件的按钮5次,它将在运行时创建5个菜单。



我想做的是点击时有另一个按钮,它将选择菜单上的任何项目(或MenuItem数组)。



请帮帮我。

解决方案

将事件添加到菜单中,如下所示 -

 myItem。点击+ =  new  
System.EventHandler(<跨度类= 代码关键字>此 .menuItemDynamicMenu_Click);





然后,只需编写处理菜单的代码点击。



C#创建动态菜单 [ ^ ]应该进一步提供i nsight。


Say I have this code in the click event:

MenuItem myItem = new MenuItem("Tab", TabIndex);
Menu1.Items.AddAt(TabIndex, myItem);
myItem.Selected = true;



Now for example I click on a button with this click event 5 times it will create 5 menu at run time.

What I want to do is to have another button that when click, it will select any item on the menu (or array of MenuItem).

Please help me with this.

解决方案

Add event to the menu as follows -

myItem .Click +=  new
    System.EventHandler(this.menuItemDynamicMenu_Click);



Then simply write code for the handled menu click.

C# Creating Dynamic Menus[^] should give further insight.


这篇关于如何在运行时选择菜单项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆