CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 19
  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!

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

    Re: Disabled MenuStrip item bug

    Okay thanks David.
    I'm going to install vb2008 without service pack now, to try and find out .
    Last edited by TT(n); January 21st, 2009 at 07:37 AM.

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

    Re: Disabled MenuStrip item bug

    dglienna,

    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.

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

    Re: Disabled MenuStrip item bug

    They don't appear.
    Code:
      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!

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

    Re: Disabled MenuStrip item bug

    Hmmm... I'm reinstalling Vista now over xp to see if thats the problem.

    Although, I'm not sure I understand the relevance of the code you're posting.
    It doesn't look remotely related to what I've illustrated.

    Please explain.

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

    Re: Disabled MenuStrip item bug

    Vista also has the same problem, with and without service pack 1.

    This is absolutely a bug. Fortuneatly, the workaround I posted works well.
    http://www.codeguru.com/forum/showpo...45&postcount=5
    Last edited by TT(n); January 16th, 2009 at 07:38 PM.

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

    Re: Disabled MenuStrip item bug

    When cursor is over OLD, change the width back to not show subitems
    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!

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

    Re: Disabled MenuStrip item bug

    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

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

    Re: [RESOLVED] Disabled MenuStrip item bug

    Not 0, the default width of the toolbar ITEM column
    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!

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

    Re: [RESOLVED] Disabled MenuStrip item bug

    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.

Page 1 of 2 12 LastLast

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured