dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 19

Thread: [RESOLVED] Disabled MenuStrip item bug

Hybrid View

  1. #1
    Join Date
    Jun 2004
    Location
    NH
    Posts
    678

    [RESOLVED] Disabled MenuStrip item bug

    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.
    Attached Images Attached Images  

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Disabled MenuStrip item bug

    Hard to say wihout ay code?
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Jun 2004
    Location
    NH
    Posts
    678

    Re: Disabled MenuStrip item bug

    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.
    Attached Files Attached Files
    Last edited by TT(n); January 16th, 2009 at 04:57 AM.

  4. #4
    Join Date
    Jun 2004
    Location
    NH
    Posts
    678

    Re: Disabled MenuStrip item bug

    Just in case it's still not clear how to reproduce the bug, I've attached a video, taken with the windows media encoder.



    EDIT:
    I just found confirmation dating back to early 2006.
    http://www.eggheadcafe.com/forumarch...st25818900.asp
    I found that bug in late 2006, so he beat me to it.
    Attached Files Attached Files
    Last edited by TT(n); January 15th, 2009 at 12:41 AM. Reason: confirmed

  5. #5
    Join Date
    Jun 2004
    Location
    NH
    Posts
    678

    Workaround

    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

  6. #6
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Disabled MenuStrip item bug

    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
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)