1

如何在按下按钮时调用方法并在释放按钮时调用另一个方法?

我正在使用 C# WinForms 应用程序中的 PTT(按下通话)按钮。

4

3 回答 3

2

使用MouseDownMouseUp 事件

于 2012-09-03T21:35:57.980 回答
2
private void button1_MouseDown(object sender, MouseEventArgs e)
{
   // button is being pressed
}

private void button1_MouseUp(object sender, MouseEventArgs e)
{
   // button was released
}
于 2012-09-03T21:38:28.847 回答
0

也许是这样的:

    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";
    }
于 2012-09-03T21:40:03.027 回答