# VBForums CodeBank > CodeBank - Visual Basic .NET >  VB.Net context menu on left click

## AlexW23

Don't know if this has been posted before

but here is an example of how to get context menu on left click

VBCODE Code:
Private Sub Form1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Click
        Dim x As Integer
        Dim y As Integer
        x = Me.MousePosition().X - Me.Location.X - 5  'Adjust Here If Needed
        y = Me.MousePosition().Y - Me.Location.Y - 23 'Adjust Here If Needed
        Dim xy As New Point(x,y)
        ContextMenu1.Show(Me, xy)
    End Sub
This is based on normal borders for anything else adjustment will need to be made.

----------


## JuggaloBrotha

and where would this code be placed for it to work?

----------


## AlexW23

Say for example in a .Click event

----------


## JuggaloBrotha

i've noticed that you use 'frmMain' and 'Me', what class is 'Me' accessing?

----------


## stanav

And where code to show the context menu?

----------


## AlexW23

updated

----------


## Troy Lundin

There are some problems with your code. You called it show ContextMenu on left click but your code does not consider which button is clicked.

Try this instead:


```
    Private Sub Form1_Click(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseClick
        If e.Button = Windows.Forms.MouseButtons.Left Then
            ContextMenu.Show(CType(sender, Control), e.Location)
        End If
    End Sub
```

Since I use the MouseClick event I can determine the button clicked. I can also use e.Location to get the location of the mouse.

Remember to replace ContextMenu with the name of your context menu.

----------

