4

Okay, so this should be a simple question, but I'm fairly new at programming, and I can't for the life of me figure out how to use a right-click event. All I want to do is call an event that does something when I right-click a picturebox. It's not in the events toolbar, and I feel like a real idiot. Any help would be greatly appreciated. I'm running the 2010 version.

Kaleo Brandt
  • 347
  • 1
  • 4
  • 12

2 Answers2

14

You can use the mouse_down event and check if it is a right-click

Private Sub PictureBox1_MouseDown(Byval sender As Object, Byval e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown

    If e.Button = MouseButtons.Right Then
        MsgBox("Right Button Clicked")
    End If

End Sub

refer to this http://www.homeandlearn.co.uk/net/nets10p2.html

Nick
  • 1,128
  • 7
  • 12
2

For those beginner C# programmers out there, this is an example written in C# for your extra information.

private void PictureBox1_MouseDown(object sender, MouseEventArgs e)
{
    if(e.Button == MouseButtons.Right)
    {
        MessageBox.Show("Right Click");
    }
}
J. Show
  • 21
  • 2
  • @DanSp. How does it not? It's the same exact code from the VB answer but translated to C# for those of us that use C# and VB it's pretty useful. If the VB answer was useful than surely so is this? – AustinWBryan Mar 22 '20 at 12:29
  • 1
    @AustinWBryan you are correct so I have adjusted what I did. – Dan Sp. Mar 25 '20 at 18:25