如何一下子关闭多个对话框?

teiunhi 2009-12-02 10:49:58
现有两个按钮A,B 点击A时 执行如下代码,

NewMail newMail = new NewMail(mailMode);
newMail.Show();

每次弹出form NewMail , 当点击多次A后, 想通过点B把所有打开的NewMail对话框全关掉, 该如何实现啊 ????

谢谢各位了!
...全文
87 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
teiunhi 2009-12-02
  • 打赏
  • 举报
回复
谢谢各位了,结贴给分
flyfly2008 2009-12-02
  • 打赏
  • 举报
回复
占位
liherun 2009-12-02
  • 打赏
  • 举报
回复
int count = 0;
private void button1_Click(object sender, EventArgs e)
{
NewMail newMail = new NewMail();
newMail.Show();
}

private void button2_Click(object sender, EventArgs e)
{
while (Application.OpenForms.Count > count)
{
Application.OpenForms[count].Close();
}
}

private void Form1_Load(object sender, EventArgs e)
{
count = Application.OpenForms.Count;
}
zhujiazhi 2009-12-02
  • 打赏
  • 举报
回复
添加一个List<Form> listForms = new List<Form>();
在show的时候,把新增的窗体添加到listForms
listForms.Add(newForm);
关闭所有窗体
foreach(From frm in listForms)
{
frm.Close();
}
teiunhi 2009-12-02
  • 打赏
  • 举报
回复
现在不想关闭主窗口,就想把NewMail 关闭了!
zl194 2009-12-02
  • 打赏
  • 举报
回复
加上这个

newMail.Show(this);

当this窗口关闭时,就都关闭了。

111,120

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧