I know there is probably a simple solution to this but it is evading me, please help.
I have created a menu that alters according to mdichild windows open - see screenshots
As I hover over the menu it refreshes by adding or removing the child windows to/from the menu. My question is, what would I use as an "Item Clicked" in my code, because the subroutines are titled by their names? This Show menu item is ShowToolStripMenuItem. As i cannot create a subroutine based on an entry that is not there at design time, how is this done? - I know it has something to do with eventhandlers and AddressOf but I have never used them. An example would be fantastic.
Examples I have checked out all use a context menu strip,
Any help will be greatly received, thanks.
I have created a menu that alters according to mdichild windows open - see screenshots
As I hover over the menu it refreshes by adding or removing the child windows to/from the menu. My question is, what would I use as an "Item Clicked" in my code, because the subroutines are titled by their names? This Show menu item is ShowToolStripMenuItem. As i cannot create a subroutine based on an entry that is not there at design time, how is this done? - I know it has something to do with eventhandlers and AddressOf but I have never used them. An example would be fantastic.
VB.NET:
Private Sub ShowToolStripMenuItem_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs) Handles ShowToolStripMenuItem.MouseHover
If ShowToolStripMenuItem.Text = "&Show" Then
If ShowToolStripMenuItem.DropDownItems.Count = 2 Then
ShowToolStripMenuItem.DropDownItems.Add("< No Image Windows >")
End If
' remove previous forms from drop down (mdi children - do this so the list is always accurate)
If ShowToolStripMenuItem.DropDownItems.Count > 2 And ShowToolStripMenuItem.DropDownItems.Item(2).Text <> "< No Image Windows >" Then
For a = ShowToolStripMenuItem.DropDownItems.Count - 1 To 2 Step -1
ShowToolStripMenuItem.DropDownItems.RemoveAt(a)
Next
End If
For Each frm As Form In Me.MdiChildren
' add image windows if they exist (mdi children)
If ShowToolStripMenuItem.DropDownItems.Count > 2 And ShowToolStripMenuItem.DropDownItems.Item(2).Text = "< No Image Windows >" Then ShowToolStripMenuItem.DropDownItems.RemoveAt(2)
ShowToolStripMenuItem.DropDownItems.Add(frm.Text)
Next
' show the user they have no images open - this catches the exception when mdi child is closed and menu doesnt refresh
If ShowToolStripMenuItem.DropDownItems.Count = 2 Then
ShowToolStripMenuItem.DropDownItems.Add("< No Image Windows >")
End If
End If
End Sub
Examples I have checked out all use a context menu strip,
VB.NET:
ShowToolStripMenuItem.DropDownItems.Add(frm.Text, New System.EventHandler(AddressOf OpenWindowAddress_Click)) <---------------------- Cannot do this here because compiler expects an image
Private Sub OpenWindowAddress_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
' add event handler code
End Sub
Any help will be greatly received, thanks.
Last edited: