WINFORM如何关闭主窗口?
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了WINFORM如何关闭主窗口?相关的知识,希望对你有一定的参考价值。
我想定时关闭主窗口,而不是子窗口
网上查到有人说
主窗口(Application.Run的窗口),不能关闭,只能隐藏
如何不用Application.Run 来创建FORM??
关闭方法: Application.Exit(); 你可以用Timer定时器来关闭并结束主窗体程序
窗体的 Close()方法才是如你所说只是隐藏,其实对象还在,可以用Show()方法再次显示出来
程序的主窗体必须用Application.Run 来创建 参考技术A 你可以先隐藏,通过时间控件定时重新显示 参考技术B 楼上正解~~~~
在winform中,关闭窗口时刷新父窗口(原来打开此窗口的窗口)
如何在关闭窗口时刷新父窗口(原来打开此窗口的窗口,不一定是mdi窗口), 这种事情在b/s里很简单,但在winform里却不那么好办。因为你不能关闭第一个窗口时再打开另一个窗口,如果这样的话新窗口就一起被关闭了。但是正因为这样,我们可以让刷新的动作在关闭子窗口时进行,当然所有的动作是在父窗口中进行的。晕,不知道说明白了没有。
还是看一下例子吧
public partial class Customer : Form
{
public Customer()
{
InitializeComponent();
}
private void customerBindingNavigatorSaveItem_Click(object sender, EventArgs e)
{
this.Validate();
this.customerBindingSource.EndEdit();
this.customerTableAdapter.Update(this.oadepotDataSet.Customer);
}
private void Customer_Load(object sender, EventArgs e)
{
// TODO: 这行代码将数据加载到表“oadepotDataSet.Customer”中。您可以根据需要移动或移除它。
this.customerTableAdapter.Fill(this.oadepotDataSet.Customer); //请注意这里
}
private void SearchBtn_Click(object sender, EventArgs e)
{
DataTable dt=customerTableAdapter.GetDataByKey("%"+QueryTextBox.ToString()+"%");
customerDataGridView.DataSource = dt;
}
private void bindingNavigatorAddNewItem_Click(object sender, EventArgs e)
{
//打开新窗口
Form addForm = new AddCustomer();
addForm.Owner = this;
addForm.ShowDialog();
this.customerTableAdapter.Fill(this.oadepotDataSet.Customer); //关键就在这里
}
请注意上面的两行红字,问题就在这里。不关子窗口什么事,所有的动作都在父窗口中完成。
以上是关于WINFORM如何关闭主窗口?的主要内容,如果未能解决你的问题,请参考以下文章
如何在winform按钮事件中用线程打开一个窗口,最后在finally中给隐藏和关闭,也就是做简单的等待窗口效果
C#winform判断子窗口是不是已关闭或在关闭的时候触发事件
C# winform 关闭窗体后在打开 如何让打开的窗体还是原窗体 且打开的窗体还是原状态