0

我正在尝试制作一个包含书签的工具条项目,每个书签都应该转到页面。如何使每个按钮工作?

    For Each b In New System.IO.DirectoryInfo("Bookmarks").GetFiles
        BookmarksToolStripMenuItem.DropDownItems.Add(b.Name)
    Next
4

1 回答 1

1

您应该首先创建一个ToolStripMenuItem,然后添加处理程序并将其放入您的工具条菜单对象,而不是向工具条菜单添加字符串对象。

For Each b In New System.IO.DirectoryInfo("Bookmarks").GetFiles
    Dim menuItem As New ToolStripMenuItem(b.Name)
    'Add any handlers here

    'Click handler to your menuItem.
    AddHandler menuItem.Click, AddressOf menuItem_Click 'CLICK EVENT HANDLER ALSO UNIQUE

    'Add menuItem to ToolStripMenu
    BookmarksToolStripMenuItem.DropDownItems.Add(menuItem)
Next


Private Sub menuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
    'CODE TO HANDLE CLICK EVENT
End Sub

如果您不知道如何动态添加处理程序,请查看示例

于 2013-10-13T21:40:23.770 回答