为动态创建的菜单添加处理程序 [英] Add Handler For Dynamically Created Menu

查看:86
本文介绍了为动态创建的菜单添加处理程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我已经创建了一个vb.net应用程序.在此应用中,我创建了动态菜单
但是问题在于如何通过单击该菜单来调用特定表格.

请帮帮我..

在此先感谢.

Hi,

I have created one vb.net application. In this app, I have created dynamic menu
But the problem is how to call particular form on click of that menu.

Please Help Me..

Thanks In Advance.

推荐答案

您的问题不清楚.
但是这里有一个解决方案,可能会回答您的问题.

我假设您在某些菜单中添加了一些按钮.
这是一些可能有效的伪代码.
Your question is not clear.
But here is a solution that might just answer your question.

I am assuming you add some buttons to some menu.
Here is some pseudo code that might work.
Public Sub AddButtonToMenu(ByVal menu As Menu)

   menu.Buttons.Add(New Button("Button 1"))
   menu.Buttons.Add(New Button("Button 2"))
   menu.Buttons.Add(New Button("Button 3"))

   For Each btn As Button In menu.Buttons
      AddHandler btn.Click, AddressOf btn_Click
   Next

End sub

Private Sub btn_Click(ByVal sender As Object, ByVal e As System.EventArgs)
   Dim btn As Button = DirectCast(sender, Button)

   If btn.Text = "Button 1" Then
   ' Do stuff when a button is clicked here.
   End If
   ' Etc.
End Sub


这篇关于为动态创建的菜单添加处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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