VB.NET 动态创建按钮上的右键单击事件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15116020/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 12:33:52  来源:igfitidea点击:

VB.NET right button click event on dynamically created button

vb.netevents

提问by pluke

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

类似于:获取单击事件中按钮的 ID/名称。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

它抱怨 e.Button: Button is not a member of System.EventArgs

Any ideas?

有任何想法吗?

回答by Abdusalam Ben Haj

Handle the MouseUpor MouseDownEvents. They pass the MouseEventArgs.

处理MouseUpMouseDown事件。他们通过MouseEventArgs.