Calling code of Button from another one in C#

2019-08-14 04:09发布

I need to know if it's possible to call the Click of a button from another one.

private void myAction_Click(object sender, EventArgs e)
{
    // int x;
    // ...
}

private void Go_Click(object sender, EventArgs e)
{
    // call the myAction_Click button
}

Thanks.

2条回答
Explosion°爆炸
2楼-- · 2019-08-14 05:02

You want:

private void Go_Click(object sender, EventArgs e)
{
    myAction_Click(sender, e);
}

But a better design is to pull the code out:

private void myAction_Click(object sender, EventArgs e)
{
    DoSomething();
}

private void Go_Click(object sender, EventArgs e)
{
    DoSomething();
}

private void DoSomething()
{
    // Your code here
}
查看更多
我命由我不由天
3楼-- · 2019-08-14 05:11
登录 后发表回答