MouseEventArgs.Button Property
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Gets which mouse button was pressed.
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
Property Value
One of the MouseButtons values.
Examples
The following code example handles the MouseDown event on a TextBox control so that clicking the right mouse button selects all the text in the control. This example requires that you have a form that contains a TextBox control named 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.ContextMenu = New ContextMenu()
End Sub
Private Sub TextBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TextBox1.MouseDown
If (e.Button = Windows.Forms.MouseButtons.Right) Then
TextBox1.Select(0, TextBox1.Text.Length)
End If
End Sub
Applies to
See also
GitHub에서 Microsoft와 공동 작업
이 콘텐츠의 원본은 GitHub에서 찾을 수 있으며, 여기서 문제와 끌어오기 요청을 만들고 검토할 수도 있습니다. 자세한 내용은 참여자 가이드를 참조하세요.
.NET