当我按下并释放按钮时,如何调用不同的方法?

时间:2012-09-03 21:32:40

标签: c# winforms button

当我按下按钮并在释放按钮时再拨打另一个按钮时,如何调用方法?

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

3 个答案:

答案 0 :(得分:2)

使用MouseDownMouseUp个活动

答案 1 :(得分:2)

private void button1_MouseDown(object sender, MouseEventArgs e)
{
   // button is being pressed
}

private void button1_MouseUp(object sender, MouseEventArgs e)
{
   // button was released
}

答案 2 :(得分: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";
    }