Here is another bug I found and never got around to posting it.
Maybe we should have an area to post these, but for now it's a topic of discussion to verify the problem exists.
I've got a few more kicking around.
Bug
If you move the mouse from an enabled menu strip item(with it's sub items open!), onto an adjacent disabled item, then any of it's sub menu items are shown.
This is ofcourse not intended behavior, and requires extra code to prevent.
Are you asking for the preventive code?
There are several different events that could be used to work around the bug, but it can get messy quickly.
I'll come up with something postable ASAP.
Sample file attached, although the picture says it all.
A disabled item, showing it's sub items.
1. To duplicate the error, you simply add a menustrip component, and add at least two sub items as shown, each having it's own sub item/s.
2. Then disable the lower one as shown. This disabled item should not be openable, and usually is not. 3. However if you open the item above it, and expose it's sub items first, then move the mouse down over the disabled item, it will open up.
Last edited by TT(n); January 16th, 2009 at 04:57 AM.
Here is a workaround for isolated cases where you have only one set of adjacent sub items with the bug.
Completely redundant, but here it is.
Code:
Private Sub NewToolStripMenuItem_DropDownClosed(ByVal sender As Object, ByVal e As System.EventArgs) Handles NewToolStripMenuItem.DropDownClosed
If OldToolStripMenuItem.Enabled = False Then
OldToolStripMenuItem.Enabled = True
OldToolStripMenuItem.HideDropDown()
OldToolStripMenuItem.Enabled = False
End If
End Sub
If you had many adjacent sub items, then you'd probably want to append the handles.
For example I've added another sub item below the disabled item, named ExitToolStripMenuItem.
Code:
Private Sub ToolStripMenuItem_DropDownClosed _
(ByVal sender As Object, ByVal e As System.EventArgs) _
Handles NewToolStripMenuItem.DropDownClosed, ExitToolStripMenuItem.DropDownClosed
If OldToolStripMenuItem.Enabled = False Then
OldToolStripMenuItem.Enabled = True
OldToolStripMenuItem.HideDropDown()
OldToolStripMenuItem.Enabled = False
End If
End Sub
Please post here if you come up with a better solution.
Last edited by TT(n); January 15th, 2009 at 02:02 AM.
Reason: better solution
Must be fixed. Just ran the 101 samples for VB 2008, and it works correctly.
Here's some of the code: \Windows Forms\Menu
Code:
' Copyright (c) Microsoft Corporation. All rights reserved.
Public Class MainForm
#Region "Event Handlers"
Private Sub MenuItem_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles FileMenu.MouseEnter, NewMenuItem.MouseEnter, Option1.MouseEnter, MoreOptions.MouseEnter, MoreOptions1.MouseEnter, MoreOptions2.MouseEnter, MoreOptions3.MouseEnter, Option2.MouseEnter, Option3.MouseEnter, OpenMenuItem.MouseEnter, ViewToolStripMenuItem1.MouseEnter, StatusStripOption.MouseEnter, CheckedListMenu.MouseEnter, AddOptionMenuItem.MouseEnter, RemoveOptionMenuItem.MouseEnter
Dim selected As ToolStripMenuItem = CType(sender, ToolStripMenuItem)
SelectedItem.Text = selected.Text
End Sub
Private Sub MenuItem_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles FileMenu.MouseLeave, NewMenuItem.MouseLeave, Option1.MouseLeave, MoreOptions.MouseLeave, MoreOptions1.MouseLeave, MoreOptions2.MouseLeave, MoreOptions3.MouseLeave, Option2.MouseLeave, Option3.MouseLeave, OpenMenuItem.MouseLeave, ViewToolStripMenuItem1.MouseLeave, StatusStripOption.MouseLeave, CheckedListMenu.MouseLeave, AddOptionMenuItem.MouseLeave, RemoveOptionMenuItem.MouseLeave
SelectedItem.Text = ""
End Sub
Private Sub NewMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NewMenuItem.Click
Me.BackColor = Color.White
End Sub
Private Sub MenuOption_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
For Each item As Object In CheckedListMenu.DropDownItems
If (TypeOf item Is ToolStripMenuItem) Then
Dim itemObject As ToolStripMenuItem = CType(item, ToolStripMenuItem)
itemObject.Checked = False
End If
Next
Dim selectedItem As ToolStripMenuItem = CType(sender, ToolStripMenuItem)
selectedItem.Checked = True
End Sub
Private Sub AddOptionMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddOptionMenuItem.Click
AddOption()
End Sub
Private Sub RemoveOptionMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RemoveOptionMenuItem.Click
Dim itemToRemove As ToolStripMenuItem = Nothing
If CheckedListMenu.DropDownItems.Count > 3 Then
itemToRemove = CType(CheckedListMenu.DropDownItems(CheckedListMenu.DropDownItems.Count - 1), ToolStripMenuItem)
Dim removeAt As Integer = CheckedListMenu.DropDownItems.Count - 1
If itemToRemove.Checked And CheckedListMenu.DropDownItems.Count > 4 Then
Dim itemToCheck As ToolStripMenuItem = CType(CheckedListMenu.DropDownItems(CheckedListMenu.DropDownItems.Count - 2), ToolStripMenuItem)
itemToCheck.Checked = True
End If
CheckedListMenu.DropDownItems.RemoveAt(removeAt)
End If
End Sub
Private Sub ComboBox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim combo As ToolStripComboBox = CType(sender, ToolStripComboBox)
Select Case combo.SelectedIndex
Case 0
MenuStrip1.Dock = DockStyle.Top
Case 1
MenuStrip1.Dock = DockStyle.Bottom
Case 2
MenuStrip1.Dock = DockStyle.Left
MenuStrip1.Width = 50
Case 3
MenuStrip1.Dock = DockStyle.Right
MenuStrip1.Width = 50
Case Else
MenuStrip1.Dock = DockStyle.Top
End Select
End Sub
Nope, it still doesn't work even with 2008(sp1 included) on xp sp3. Both converted and new projects failed!
It won't be till tomorro, when I get Vista back on my laptop to test it thouroughly on that.
Are you sure you are reproducing the bug the same way? A disabled item, should not show it's sub items, just because an enabled item is showing it's sub items.
Private Sub ComboBox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim combo As ToolStripComboBox = CType(sender, ToolStripComboBox)
Select Case combo.SelectedIndex
Case 0
MenuStrip1.Dock = DockStyle.Top
Case 1
MenuStrip1.Dock = DockStyle.Bottom
Case 2
MenuStrip1.Dock = DockStyle.Left
MenuStrip1.Width = 50
Case 3
MenuStrip1.Dock = DockStyle.Right
MenuStrip1.Width = 50
Case Else
MenuStrip1.Dock = DockStyle.Top
End Select
End Sub
I tried that and it does not work using the mouseenter, or mousehover event.
Code:
Private Sub OldToolStripMenuItem_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles OldToolStripMenuItem.MouseEnter
OldToolStripMenuItem.Width = 0
End Sub
Private Sub OldToolStripMenuItem_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs) Handles OldToolStripMenuItem.MouseHover
OldToolStripMenuItem.Width = 0
End Sub
Not 0, the default width of the toolbar ITEM column
I think further discussion is mute, since I've already resolved the thread, but if you have a shorter code then please post it.
I've tried several integer values for the width, and none make any difference, because of the event bug I assume.
You still haven't answered my question from post #10, so I'm a little impatient for an explaination, that would help me identify your confusion.
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.