本文介绍了为什么我的事件没有解雇?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在表单中添加了一个contextmenustrip,并将其命名为Namelist。 contextmenu显示我在运行时添加的菜单项,但它的事件不会触发?
私有 Sub Form1_Load(发件人作为 对象,e As EventArgs)句柄 MyBase .Load
Dim name As 字符串 = Menu1
Dim MyMenuItem As 新 MenuItem
MyMenuItem.Text = name
AddHandler MyMenuItem.Click, AddressOf MyMenuItems_Click
Namelist.Items .Add(name)
name = Menu2
MyMenuItem = 新 MenuItem
MyMenuItem.Text = name
AddHandler MyMenuItem.Click, AddressOf Me .MyMenuItems_Click
Namelist.Items.Add(name)
结束 Sub
私有 Sub MyMenuItems_Click( ByVal sender As System 。对象, ByVal e 作为系统。 EventArgs)
Dim MyMenu As MenuItem = CTy pe (sender,MenuItem)
选择 案例 MyMenu.Text
案例 Menu1
MessageBox.Show( 单击了Menu1)
大小写 Menu2
MessageBox.Show( 单击了Menu2)
结束 选择
结束 Sub
私有 Sub Form1_MouseDoubleClick(sender As Object ,e As MouseEventArgs)句柄 我 .MouseDoubleClick
Namelist.Show( Me ,eX,eY)
结束 Sub
任何人?
解决方案
I Have added a contextmenustrip to my form and called it Namelist. The contextmenu shows the menuitems I add at runtime, but the event for it does not fire?
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load Dim name As String = "Menu1" Dim MyMenuItem As New MenuItem MyMenuItem.Text = name AddHandler MyMenuItem.Click, AddressOf MyMenuItems_Click Namelist.Items.Add(name) name = "Menu2" MyMenuItem = New MenuItem MyMenuItem.Text = name AddHandler MyMenuItem.Click, AddressOf Me.MyMenuItems_Click Namelist.Items.Add(name) End Sub Private Sub MyMenuItems_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Dim MyMenu As MenuItem = CType(sender, MenuItem) Select Case MyMenu.Text Case "Menu1" MessageBox.Show("Menu1 was clicked") Case "Menu2" MessageBox.Show("Menu2 was clicked") End Select End Sub Private Sub Form1_MouseDoubleClick(sender As Object, e As MouseEventArgs) Handles Me.MouseDoubleClick Namelist.Show(Me, e.X, e.Y) End Sub
Anyone?
解决方案
这篇关于为什么我的事件没有解雇?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!