none
[Help] Show contextual menu when clicking RRS feed

  • Question

  • Hello friends

    I have a button on a form that I would like to know that when you click, the context menu appears with the left button, that is, the opposite.

    Thank you
    Monday, May 22, 2017 9:42 PM

Answers

  •  So what is wrong with just using the Show method of the ContextMenuStrip in the Button Click event?

        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            ContextMenuStrip1.Show(MousePosition)
        End Sub
    
     

     


    If you say it can`t be done then i`ll try it

    • Marked as answer by Symantecc Monday, May 22, 2017 10:22 PM
    Monday, May 22, 2017 10:19 PM

All replies

  • Hello friends

    I have a button on a form that I would like to know that when you click, the context menu appears with the left button, that is, the opposite.

    Thank you

    Do you maybe mean a SplitButton?


    "A problem well stated is a problem half solved.” - Charles F. Kettering

    Monday, May 22, 2017 9:53 PM
  • Hi fran, thanks for replying.

    It's just a button :)
    Monday, May 22, 2017 9:57 PM
  • Hi fran, thanks for replying.

    It's just a button :)

    Well I was just thinking that would be confusing to use - no?

    *****

    Be patient - there are some really brilliant people here and I'm sure you'll get some good ideas before too long. :)


    "A problem well stated is a problem half solved.” - Charles F. Kettering

    Monday, May 22, 2017 10:00 PM
  • Yes, but what I want to do is that when the click is shown and not displayed with the opposite side of the mouse
    Monday, May 22, 2017 10:02 PM
  •  So what is wrong with just using the Show method of the ContextMenuStrip in the Button Click event?

        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            ContextMenuStrip1.Show(MousePosition)
        End Sub
    
     

     


    If you say it can`t be done then i`ll try it

    • Marked as answer by Symantecc Monday, May 22, 2017 10:22 PM
    Monday, May 22, 2017 10:19 PM
  • Ah, good work IR.

    That's the equivalent of a SplitButton:

    https://msdn.microsoft.com/en-us/library/windows/desktop/dd940505(v=vs.85).aspx


    "A problem well stated is a problem half solved.” - Charles F. Kettering


    Monday, May 22, 2017 10:26 PM
  •  You could also use the MouseDown event of the Button if you want to make sure that only the left mouse button will activate the ContextMenuStrip.  This would not show the ContextMenuStrip if the button has focus and the user presses Enter or Space Bar like the Click event will.

        Private Sub Button1_MouseDown(sender As Object, e As MouseEventArgs) Handles Button1.MouseDown
            If e.Button = MouseButtons.Left Then
                ContextMenuStrip1.Show(MousePosition)
            End If
        End Sub
    


    If you say it can`t be done then i`ll try it

    Monday, May 22, 2017 10:26 PM
  • Ah, good work IR.

    That's the equivalent of a SplitButton:

    https://msdn.microsoft.com/en-us/library/windows/desktop/dd940505(v=vs.85).aspx


    "A problem well stated is a problem half solved.” - Charles F. Kettering



     Yes,  pretty much the same thing.  However, a SplitButton is only available on a ToolStrip menu though,  i believe.  So,  if OP is not using a ToolStrip,  there is no SplitButton available.  8)

    If you say it can`t be done then i`ll try it

    • Edited by IronRazerz Monday, May 22, 2017 10:41 PM
    Monday, May 22, 2017 10:39 PM
  • ... there is no SplitButton available.  8)

    If you say it can`t be done then i`ll try it

    Yet ... be patient!

    That one is Dev, but I've seen many times that they (Dev and MSFT) seem to be in a cat and mouse chase about who leads and who follows, so who knows. ;-)


    "A problem well stated is a problem half solved.” - Charles F. Kettering

    Monday, May 22, 2017 10:48 PM
  •  I doubt they will do anything for windows forms but,  maybe for WPF.  I did not look but, WPF might already have something similar.  It would not be hard to make a small button class to do this though.  All it would really require is lining the ContextMenuStrip up with the bottom left of the button....

        Private Sub Button1_MouseDown(sender As Object, e As MouseEventArgs) Handles Button1.MouseDown
            If e.Button = MouseButtons.Left Then
                Dim ptc As Point = Me.PointToScreen(Button1.Location)
                ContextMenuStrip1.Show(New Point(ptc.X, ptc.Y + Button1.Height))
            End If
        End Sub
    
     

     


    If you say it can`t be done then i`ll try it

    Monday, May 22, 2017 11:08 PM
  • IR,

    If anyone here can make it - it'd be you!

    Give it thought. I bet you're on to something. ;)


    "A problem well stated is a problem half solved.” - Charles F. Kettering

    Monday, May 22, 2017 11:11 PM