如何在按下按钮时调用方法并在释放按钮时调用另一个方法?
我正在使用 C# WinForms 应用程序中的 PTT(按下通话)按钮。
private void button1_MouseDown(object sender, MouseEventArgs e)
{
// button is being pressed
}
private void button1_MouseUp(object sender, MouseEventArgs e)
{
// button was released
}
也许是这样的:
private void btn1_MouseDown(object sender, MouseEventArgs e)
{
Console.WriteLine("Mouse Button was pressed down on the button");
}
private void btn1_MouseUp(object sender, MouseEventArgs e)
{
Console.WriteLine("Mouse button Button was released");
}
单击按钮后查看输出窗口。
好的,试试这个,在表单中添加一个文本框并将其命名为 TextBox1,然后将此代码添加到后面的代码中:
private void btn1_MouseDown(object sender, MouseEventArgs e)
{
this.TextBox1.Text = "Mouse Button was pressed down on the button";
}
private void btn1_MouseUp(object sender, MouseEventArgs e)
{
this.TextBox1.Text = "Mouse button Button was released";
}