呼叫按钮的code从另外一个在C# [英] Calling code of Button from another one in C#

查看:82
本文介绍了呼叫按钮的code从另外一个在C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要知道,如果有可能调用点击按钮从另一个。

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
}

感谢。

推荐答案

您想要的:

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


但是,一个更好的设计就是拉code OUT:


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
}

这篇关于呼叫按钮的code从另外一个在C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆