MouseEventArgs.Button 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
會知道是哪個滑鼠按鍵被按下的。
public:
property System::Windows::Forms::MouseButtons Button { System::Windows::Forms::MouseButtons get(); };
public System.Windows.Forms.MouseButtons Button { get; }
member this.Button : System.Windows.Forms.MouseButtons
Public ReadOnly Property Button As MouseButtons
屬性值
這是其中一項 MouseButtons 價值。
範例
以下程式碼範例處理 MouseDown 控制項上的 TextBox 事件,點擊滑鼠右鍵即可選取控制項中的所有文字。 這個範例要求你有一個包含 TextBox 名為 textBox1的控制項的表單。
private void Form1_Load(object sender, EventArgs e)
{
// This line suppresses the default context menu for the TextBox control.
textBox1.ContextMenu = new ContextMenu();
textBox1.MouseDown += new MouseEventHandler(textBox1_MouseDown);
}
void textBox1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
textBox1.Select(0, textBox1.Text.Length);
}
}
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
TextBox1.ContextMenuStrip = New ContextMenuStrip()
End Sub
Private Sub TextBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TextBox1.MouseDown
If (e.Button = MouseButtons.Right) Then
TextBox1.Select(0, TextBox1.Text.Length)
End If
End Sub