winform 程序

.Net技术 码拜 8年前 (2016-03-06) 933次浏览
本人有很多个按钮事件都是点击弹出一个提示框,操作成功。现在要设置一个一键操作全部其他按钮。怎么设置才可以只弹出一个提示框,而不是把每个按钮的提示框都弹出?
解决方案

40

可以重构你的代码,例如

void Button1_Click(object sender, EventArgs e)
{
    // 做法1具体细节
    MessageBox("做法1完成");
}
void Button1_Click(object sender, EventArgs e)
{
    // 做法2具体细节
    MessageBox("做法2完成");
}

可以改成:

void Button1_Click(object sender, EventArgs e)
{
    做法1();
    MessageBox("做法1完成");
}
void Button1_Click(object sender, EventArgs e)
{
    做法2();
    MessageBox("做法2完成");
}
void ButtonAll_Click(object sender, EventArgs e)
{
    做法1();
    做法2();
    MessageBox("做法1、2完成");
}
void 做法1()
{
    // 做法1具体细节
}
void 做法2()
{
    // 做法2具体细节
}

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明winform 程序
喜欢 (0)
[1034331897@qq.com]
分享 (0)