关闭windows窗体不退出整个应用程序 [英] Close a windows form without exiting the entire application

查看:983
本文介绍了关闭windows窗体不退出整个应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

环保




  • 的Windows XP SP3 X32

  • 的Visual Studio 2005标准

  • 设备/平台:霍尼韦尔海豚9500与Windows Mobile / Pocket PC的2003

  • .NET框架1.1和.NET Compact Framework框架1.0 SP3






目标



我目前有3种形式的应用程序。第一种形式是像一个闪屏,但我还没有决定用户是否将被允许重新打开它。第二种形式是项目的集合列表将被显示,一个接一个,在第三表格



我想能够打开第一形式和等待按下按钮。当按下该按钮,我想开了另一种形式的第一处理。一旦项目被选中出了第二屏幕上的列表框,我想显示的第三种形式以及可能处置第二种形式。用户还需要能够重新打开所述第二形式来选择要显示的第三形态上的另一个项目。话虽这么说,我可能不想处理第二种形式。然而,记忆是这个设备(64MB存储与系统内存共享),因此我的愿望,处理事情时,我可以对一个问题。






问题



您或许可以标题猜测这一点,但是当我结束我的第一种形式/处置,整个应用程序关闭。现在,我已经读了对此事一点,据我所知,这与该行办:Application.Run(新Form1的());或不管我的形式恰好被命名。






的东西我都试过




  • this.Dispose() - 关闭整个应用程序

  • this.Close() - 关闭整个应用程序

  • 我也看到多人建议使用一个实例化的表格(表格F1 =新建MyForm()),显示它(.Show()),然后用Application.Run();不带任何参数。当我尝试,我得到的方法没有过载运行取0参数

  • 的ApplicationContext不会在.NET Framework
  • $ B的1.1版本存在$ b





代码



 静态无效的主要()
{
Application.Run(新的欢迎());
}

私人无效btnBegin_Click(对象发件人,EventArgs五)
{
组成WOF =新WorkOrderForm();
wof.Show();
wof.BringToFront();

//这里就是我想处置欢迎形式
}


的< DIV CLASS =h2_lin>解决方案

您可以调用Application.Run()与你的主的形式,这将仍然允许在窗体关闭应用程序正常关闭,但其隐藏(可见= FALSE),而你显示启动画面,或者只显示在它上面的启动画面。


Environment

  • Windows XP SP3 x32
  • Visual Studio 2005 Standard
  • Device/Platform: Honeywell Dolphin 9500 with Windows Mobile/Pocket PC 2003
  • NET Framework 1.1 and .NET Compact Framework Framework 1.0 SP3

Goal

I currently have an application with 3 forms. The first form is something like a splash screen but I have not yet decided whether or not the user will be allowed to reopen it. The second form is an aggregate listing of items that will be displayed, one by one, in the third form.

I would like to be able to open the first form and wait for a button press. When that button is pressed, I would like to open another form and dispose of the first. Once an item is selected out of the list box on the second screen, I would like to display the third form and possibly dispose of the second form. The user also needs to be able to reopen the second form to select another item to be displayed on the third form. That being said, I probably don't want to dispose of the second form. However, memory is an issue on this device (64MB shared between storage and system memory) hence my desire to dispose of things when I can.


Problem

You can probably guess this by the title, but when I close/dispose of my first form, the entire application closes. Now that I have read up on the matter a little, I am aware that this has to do with this line: Application.Run(new Form1()); or whatever my form happens to be named.


Things I Have Tried

  • this.Dispose() - closes the entire application
  • this.Close() - closes the entire application
  • I also saw multiple people recommending one instantiate their form (Form f1 = new MyForm();), show it (.Show();), and then use Application.Run(); with no arguments. When I try this, I get "No overload for method 'Run' takes '0' arguments"
  • ApplicationContext does not exist in version 1.1 of the .NET Framework

Code

static void Main()
  {
   Application.Run(new Welcome());
  }

  private void btnBegin_Click(object sender, EventArgs e)
  {
   Form wof = new WorkOrderForm();
   wof.Show();
   wof.BringToFront();

   // Here is where I would like to dispose of the Welcome form
  }

解决方案

You can call Application.Run() with your "main" form, this will still allow the application to close properly when the form closes, but hide it (Visible=false) whilst you show the splash screen, or just show the splash screen on top of it.

这篇关于关闭windows窗体不退出整个应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆