【问题标题】:Calling code of Button from another one in C#从 C# 中的另一个调用 Button 的代码
【发布时间】:2011-08-24 12:43:56
【问题描述】:

我需要知道是否可以从另一个按钮调用单击按钮。

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

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

谢谢。

【问题讨论】:

  • 为什么要再次点击按钮?

标签: c# .net button click action


【解决方案1】:

你想要:

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

但更好的设计是把代码拉出来:

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

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

private void DoSomething()
{
    // Your code here
}

【讨论】:

  • 谢谢它的工作,我想我会将代码放在另一个函数中,并在两个按钮中调用。
【解决方案2】:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多