0

I have a Winforms app with a Toolstrip and Datagridview.

I'm attempting to implement MouseWheeling on the ToolStripMenuItems based on some information here:

I have added a Mousewheel event to the DataGridView as adding one to the base form didn't fire. My problem is that I can't find a way to detect when the mouse cursor is over an open ToolstripMenu, it always says that it's over the DataGridView.

I have tried several different approaches including the current code:

    Public Shared Function FindControlAtPoint(container As Control, pos As Point) As Control
        Dim child As Control
        For Each c As Control In container.Controls
            If c.Visible AndAlso c.Bounds.Contains(pos) Then
                child = FindControlAtPoint(c, New Point(pos.X - c.Left, pos.Y - c.Top))
                If child Is Nothing Then
                    Return c
                Else
                    Return child
                End If
            End If
        Next
        Return Nothing
    End Function

    Public Shared Function FindControlAtCursor(form As Form) As Control
        Dim pos As Point = Cursor.Position
        If form.Bounds.Contains(pos) Then
            Return FindControlAtPoint(form, form.PointToClient(Cursor.Position))
        End If
        Return Nothing
    End Function

1 Mouse wheel scrolling Toolstrip menu items

Community
  • 1
  • 1
user3329538
  • 289
  • 1
  • 5
  • 12
  • Have you tried with the MouseHover/MouseEnter Events of the ToolStripMenuItem? – varocarbas Feb 26 '14 at 14:34
  • I'm working on this now, to make a class variable to track the entry and exits. Is there no way to tell if the mouse if over the toolstripmenuitem? – user3329538 Feb 27 '14 at 11:07
  • I have to attach the Mousewheel event to the datagridview to get it to fire, is there a way to stop the datagridview itself to stop scrolling? – user3329538 Feb 27 '14 at 11:08
  • Can you please read, understand and implement/test my suggestion, instead of keep focusing on your problem? These events are triggered whenever the mouse is over the given item, you don't need to do anything else. All your code can be replace with one of this events. – varocarbas Feb 27 '14 at 11:11
  • Hi @varocarbas, I have been working on this for the past couple of hours. I implemented MouseEnter and MouseLeave events to track if I am over an item. How do I track the Mousewheel event though in this case? – user3329538 Feb 27 '14 at 11:27
  • What you mean with track? Imagine that you have a contextMenu with 3 items; and you use the mouse wheel to move from item 2 to item 1. If you rely on, for example, MouseEnter in both items, this event should be triggered whenever the mouse "enters on it", independently upon how it reaches there (via mousewheel or normal movement). Can you please elaborate a bit more on the exact problem you want to solve? – varocarbas Feb 27 '14 at 11:32
  • @varocarbas I have a long contextmenu something like this: http://i.stack.imgur.com/XUZWZ.png I'm looking to implement mousewheeling on it by simulating the UP and DOWN keys. – user3329538 Feb 27 '14 at 12:22
  • Please, bear in mind that the whole point of writing a comment is giving you some hint; not starting a whole discussion (for this I would have written an answer). You should update your post with any relevant information. BUT still I don't see the exact point of what you are saying and why MouseEnter is not working with you (it is triggered every time the mouse "enters" the item)! Please, update your question with all this information, with all the code you have tried (including the MouseEnter/Hover events) and explain clearly (an example always helps) why it does not deliver what you want. – varocarbas Feb 27 '14 at 12:27
  • I have spent a long enough time on this already (and sorry but quite a few askers have proven me that being nice and keen of helping is a very bad idea with some people, not sure if your case)... also bear in mind that I am not here to explain you how to post a clear question (you should have done an effort by your own)... Let me know once you have updated your post; if I see everything clearly explained, I might answer; otherwise, you should wait for the next helper. – varocarbas Feb 27 '14 at 12:30

0 Answers0