vb.net动态菜单,如何添加事件?
添加了一个菜单控件ContextMenuStrip1,改名rtMenu。在循环中添加菜单项。fori=0to4rtMenu.Items.Add(i)nexti这样就有5个...
添加了一个菜单控件ContextMenuStrip1,改名rtMenu。
在循环中添加菜单项。
for i=0 to 4
rtMenu.Items.Add(i)
next i
这样就有5个菜单选择了,但如何分别给他们添加事件呢?或者说分别点击它们后,如何去执行相应的代码呢? 展开
在循环中添加菜单项。
for i=0 to 4
rtMenu.Items.Add(i)
next i
这样就有5个菜单选择了,但如何分别给他们添加事件呢?或者说分别点击它们后,如何去执行相应的代码呢? 展开
3个回答
展开全部
动态生成的控件:
Private Sub UserControl1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Dim myPicture = New System.Windows.Forms.PictureBox()
Me.Panel3.Controls.Add(myPicture)
myPicture.Size = New System.Drawing.Size(115, 160)
myPicture.TabStop = False
myPicture.Name = "p"
myPicture.Cursor = Cursors.Hand
AddHandler myPicture.Click, AddressOf mypic_Click '添加事件
End Sub
处理事件的过程:
Private Sub mypic_Click() 'ByVal id As String
Dim bookInfo As New BookInfo
bookInfo.Show()
Me.Parent.Enabled = False
展开全部
for i=0 to 4
rtMenu.Items.Add(i)
AddHandler rtMenu.Items(i).Click, AddressOf EventOfMenu 'EventOfMenu是事件名称
next i
rtMenu.Items.Add(i)
AddHandler rtMenu.Items(i).Click, AddressOf EventOfMenu 'EventOfMenu是事件名称
next i
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
for i=0 to 4
rtMenu.Items.Add(i)
AddHandler rtMenu.Items(rtMenu.Items.Count).Click, AddressOf ComMouseClicked
next i
Private Sub ComMouseClicked(ByVal sender As Object, ByVal e As System.EventArgs)
Select Case CType(sender, ContextMenuStrip).Text
Case "菜单1"
‘菜单1的代码
Case "菜单2"
‘菜单2的代码
End Select
End Sub
rtMenu.Items.Add(i)
AddHandler rtMenu.Items(rtMenu.Items.Count).Click, AddressOf ComMouseClicked
next i
Private Sub ComMouseClicked(ByVal sender As Object, ByVal e As System.EventArgs)
Select Case CType(sender, ContextMenuStrip).Text
Case "菜单1"
‘菜单1的代码
Case "菜单2"
‘菜单2的代码
End Select
End Sub
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询