如何关闭c# 加载后的form

来源:百度知道 编辑:UC知道 时间:2024/07/02 19:03:25
from 1=new from
1.ShowDialog();
this.close();或者 this.hide();
加载几次后出现了很多FROM的窗口,如何把它们关闭,只留下一个!!!

private void CloseProcess()
{
Process[] Processes = Process.GetProcesses();
foreach (Process myProcess in Processes)
{
//MessageBox.Show(myProcess.ProcessName);
if (myProcess.ProcessName == "from")
{
myProcess.Kill();
myProcess.Dispose();
}
}
}
调用此方法 结束关联进程

把ShowDialog()
换成Show()
再用this。Close()就行了
前提是当前这个窗口不是程序开始运行时启动的第一个窗口

from 1=new from
1.ShowDialog(this);

加个this,试试看!

appliaction.exit

this.close()就可以关闭,但是关闭的是当前窗体
LZ看看自己是不是写错地方了