我正在尝试构建一个数据库驱动的 VB.Net 应用程序,该应用程序从数据库中提取注册帐户列表并在菜单中显示 throes 帐户的用户名,因此用户可以选择一个并打开一个新表单(他们在其中使用它)。
到目前为止,我所拥有的是 MDI 父窗口的构造函数
Public Sub New()
InitializeComponent()
Dim tsmi As New ToolStripMenuItem("Users", Nothing, AddressOf users_mousedown)
MenuStrip1.Items.Add(tsmi)
End Sub
用户菜单的处理程序(其中SQLite_db
是一个负责数据库user_class
的类,并且是一个具有两个项目(用户名和密码)作为字符串的类。
Sub users_mousedown()
Dim submenu As New ContextMenuStrip
Dim database As New SQLite_db
Dim user_list As New List(Of user_class)
user_list = database.List_Users
For Each user As user_class In user_list
submenu.Items.Add(user.username, Nothing, AddressOf Open_new_window(user))
Next
submenu.Items.Add("Add new user", Nothing, AddressOf AddNew)
submenu.Show(Control.MousePosition)
End Sub
我想要发生的是当用户单击上下文菜单时,会创建一个新的 MDI 子表单并传递用户中的数据,但是因为 AddressOf 不喜欢传递数据,所以这不起作用......
I've looked at delegates and landa expressions but don't think either of them do what I need, the other option is to make my own subclass of the ContextMenuStrip class, which 1) handles the clicks the way I want to and 2) sounds like a nightmare.
Before I launch into what I think will be a hell of a lot of work, am I missing something? is their a simple way to do what I want to do? or if not will sub-classing ContextMenuStrip work and if not any ideas as to what will (and if it will, any ideas as to how to start learning how to do that)