pluke
pluke

Reputation: 4346

VB.NET right button click event on dynamically created button

Similar to: Get the ID/Name of a button in a click event. VB.NET ?

I am looking to find whether the left or right button was clicked on a mouse. I have declared a block class which holds buttons. I've assigned an event to the button click through:

Class Block
  Public X As Integer
  Public Y As Integer
  Public type As String
  Public status As String
  Public text As String
  Public WithEvents button As Button

  Private Sub btnReveal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button.Click
  ....
  ....
  End Sub

This works fine, but when I try to pick up the right button click using:

    If e.Button = MouseButtons.Right Then
        MessageBox.Show("RH click")
    Else
        button.Text = text
        button.BackColor = Color.LightGray
    End If

It complains on e.Button: Button is not a member of System.EventArgs

Any ideas?

Upvotes: 1

Views: 6392

Answers (1)

Abdusalam Ben Haj
Abdusalam Ben Haj

Reputation: 5423

Handle the MouseUp or MouseDown Events. They pass the MouseEventArgs.

Upvotes: 4

Related Questions