扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:阿虎 来源:天极开发者网络 2007年11月9日
关键字:
Private Sub Button1_Click ( ByVal sender As System.Object , ByVal e As System.EventArgs ) Handles Button1.Click Dim MainMenu1 As MainMenu = New MainMenu ( ) '创建一个MainMenu实例 Dim myMenuItem1 As MenuItem = New MenuItem ( ) Dim myMenuItem2 As MenuItem = New MenuItem ( ) Dim myMenuItem3 As MenuItem = New MenuItem ( ) Dim myMenuItem4 As MenuItem = New MenuItem ( ) myMenuItem1.Text = "文件(&F)" myMenuItem2.Text = "新建(&N)" myMenuItem3.Text = "-" myMenuItem4.Text = "打开(&O)" '创建四个MenuItem实例,并进行相应设置 myMenuItem1.MenuItems.Add ( myMenuItem2 ) myMenuItem1.MenuItems.Add ( myMenuItem3 ) myMenuItem1.MenuItems.Add ( myMenuItem4 ) '以myMenuItem1是myMenuItem2、myMenuItem3和myMenuItem4的父菜单项 MainMenu1.MenuItems.Add ( myMenuItem1 ) '在MainMenu实例中加入MainItem实例 Me.Menu = MainMenu1 '把MainMenu1指派给Form的的Menu属性,这样下拉菜单才能够显示 Button1.Enabled = False End Sub |
Private Sub Button2_Click ( ByVal sender As System.Object , ByVal e As System.EventArgs ) Handles Button2.Click Dim ContextMenu1 As ContextMenu = New ContextMenu ( ) '创建一个ContextMenu实例 Dim myMenuItem1 As MenuItem = New MenuItem ( ) Dim myMenuItem2 As MenuItem = New MenuItem ( ) Dim myMenuItem3 As MenuItem = New MenuItem ( ) myMenuItem1.Text = "拷贝(&C)" myMenuItem2.Text = "剪切(&X)" myMenuItem3.Text = "粘贴(&V)" '创建三个MenuItem实例,并进行相应设置 ContextMenu1.MenuItems.Add ( myMenuItem1 ) ContextMenu1.MenuItems.Add ( myMenuItem2 ) ContextMenu1.MenuItems.Add ( myMenuItem3 ) '在ContextMenu1中加入MenuItem Me.ContextMenu = ContextMenu1 '把ContextMenu1指派给Form的ContextMenu属性,显示弹出菜单 Button2.Enabled = False End Sub |
Dim MainMenu1 As MainMenu = New MainMenu ( ) '创建一个MainMenu实例 Dim myMenuItem1 As MenuItem = New MenuItem ( ) Dim myMenuItem2 As MenuItem = New MenuItem ( ) Dim myMenuItem3 As MenuItem = New MenuItem ( ) Dim myMenuItem4 As MenuItem = New MenuItem ( ) Dim myMenuItem5 As MenuItem = New MenuItem ( ) Dim myMenuItem6 As MenuItem = New MenuItem ( ) myMenuItem1.Text = "文件(&F)" myMenuItem2.Text = "新建(&N)" myMenuItem3.Text = "-" myMenuItem4.Text = "打开(&O)" myMenuItem5.Text = "新建项目" myMenuItem6.Text = "新建文件" '创建四个MenuItem实例,并进行相应设置 myMenuItem2.MenuItems.Add ( myMenuItem5 ) myMenuItem2.MenuItems.Add ( myMenuItem6 ) 'myMenuItem2是myMenuItem5和myMenuItem6的父菜单项 myMenuItem1.MenuItems.Add(myMenuItem2) myMenuItem1.MenuItems.Add ( myMenuItem3 ) myMenuItem1.MenuItems.Add ( myMenuItem4 ) '以myMenuItem1是myMenuItem2、myMenuItem3和myMenuItem4的父菜单项 MainMenu1.MenuItems.Add ( myMenuItem1 ) '在MainMenu实例中加入MainItem实例 Me.Menu = MainMenu1 '把MainMenu1指派给Form的的Menu属性,这样下拉菜单才能够显示 |
图06:动态创建存在子菜单的下拉菜单 |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者