Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. ContextMenuStrip not highlighting Items according to mouse movement

ContextMenuStrip not highlighting Items according to mouse movement

Scheduled Pinned Locked Moved Visual Basic
help
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Trevortni
    wrote on last edited by
    #1

    I have a ContextMenuStrip that I am showing programmatically in response to a button being clicked. Everything works as expected, except that the Items in the menu do not respond to being moused over. Whether the mouse button is up or down, mousing over the menu has no visible effect, and releasing the mouse button does not select an Item, as expected. Performing a full click on an Item does still activate the Item, however. Here's my code for showing the ContextMenuStrip:

    Protected Overrides Sub OnMouseDown(ByVal e As System.Windows.Forms.MouseEventArgs)
    MyBase.OnMouseDown(e)
    If Enabled Then
    m_MouseDown = True
    If m_State > ButtonState.MousePressed Then
    m_State = ButtonState.MousePressed
    End If
    Invalidate()
    If DropDown IsNot Nothing AndAlso DropDown.Items.Count > 0 Then
    If ShowMenu Then
    ShowMenu = False
    ElseIf arrowRect.Contains(PointToClient(MousePosition)) Then
    ShowMenu = True
    m_MouseHeldWhileOpened = True
    DropDown.Capture = True
    End If
    End If
    End If
    End Sub

    Protected Property ShowMenu() As Boolean
    Get
    Return m_showMenu
    End Get
    Set(ByVal value As Boolean)
    If value <> m_showMenu Then
    m_ShowMenu = value
    If m_ShowMenu Then
    m_DropDown.Show(Me, GetDropDownSpawnPoint, DropDownDirection)
    m_State = ButtonState.MenuUp
    If m_DropDown.ClientRectangle.Contains(PointToScreen(MousePosition)) Then
    m_DropDown.Capture = True
    End If
    Else
    m_DropDown.Close()
    ElevateState()
    End If
    End If
    End Set
    End Property

    I have tried a number of different ideas to get the menu to respond correctly, some of which attempts are still evident in the code here. If any help would be forthcoming, it would be greatly appreciated - nobody else on Google seems to have experienced this problem. Thank you in advance for any help you can offer.

    D 1 Reply Last reply
    0
    • T Trevortni

      I have a ContextMenuStrip that I am showing programmatically in response to a button being clicked. Everything works as expected, except that the Items in the menu do not respond to being moused over. Whether the mouse button is up or down, mousing over the menu has no visible effect, and releasing the mouse button does not select an Item, as expected. Performing a full click on an Item does still activate the Item, however. Here's my code for showing the ContextMenuStrip:

      Protected Overrides Sub OnMouseDown(ByVal e As System.Windows.Forms.MouseEventArgs)
      MyBase.OnMouseDown(e)
      If Enabled Then
      m_MouseDown = True
      If m_State > ButtonState.MousePressed Then
      m_State = ButtonState.MousePressed
      End If
      Invalidate()
      If DropDown IsNot Nothing AndAlso DropDown.Items.Count > 0 Then
      If ShowMenu Then
      ShowMenu = False
      ElseIf arrowRect.Contains(PointToClient(MousePosition)) Then
      ShowMenu = True
      m_MouseHeldWhileOpened = True
      DropDown.Capture = True
      End If
      End If
      End If
      End Sub

      Protected Property ShowMenu() As Boolean
      Get
      Return m_showMenu
      End Get
      Set(ByVal value As Boolean)
      If value <> m_showMenu Then
      m_ShowMenu = value
      If m_ShowMenu Then
      m_DropDown.Show(Me, GetDropDownSpawnPoint, DropDownDirection)
      m_State = ButtonState.MenuUp
      If m_DropDown.ClientRectangle.Contains(PointToScreen(MousePosition)) Then
      m_DropDown.Capture = True
      End If
      Else
      m_DropDown.Close()
      ElevateState()
      End If
      End If
      End Set
      End Property

      I have tried a number of different ideas to get the menu to respond correctly, some of which attempts are still evident in the code here. If any help would be forthcoming, it would be greatly appreciated - nobody else on Google seems to have experienced this problem. Thank you in advance for any help you can offer.

      D Offline
      D Offline
      DaveAuld
      wrote on last edited by
      #2

      What are you trying to do that you have all this code in the mousedown events? Whenever i have used context menu's in the past i haven't gone to all that trouble. For example, the code below is handles on a button.click, It creates a new context menu, adds to click handlers for the menus events and shows the menu next to the button.

      Private Sub ButtonSave\_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonSave.Click
      
          Dim theMenu As New ContextMenuStrip
      
          theMenu.Items.Add("Export to XML", MenuExportXML.Image, AddressOf MenuExportXML\_Click)
          theMenu.Items.Add("Export to CSV", MenuExportCSV.Image, AddressOf MenuExportCSV\_Click)
      
          Dim p As New Point
          p.X = ButtonSave.Width
          p.Y = ButtonSave.Top
      
          theMenu.Show(ButtonSave, p)
      
      End Sub
      

      Dave Don't forget to rate messages!
      Find Me On: Web|Facebook|Twitter|LinkedIn
      Waving? dave.m.auld[at]googlewave.com

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups