簡體   English   中英

在C#中從另一個調用Button的代碼

[英]Calling code of Button from another one in C#

我需要知道是否可以從另一個按鈕中調用“單擊按鈕”。

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);
}

但是更好的設計是將代碼提取出來:

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

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

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM