简体   繁体   English

从另一个Windows窗体关闭Windows窗体

[英]close a windows form from another windows form

I am working windows mobile application in compact framework 3.5.I want to close a windows form from another windows form. 我正在紧凑框架3.5中工作Windows Mobile应用程序。我想从另一个Windows窗体中关闭Windows窗体。

I tried like below, 我尝试如下

Book newform = (Book)Application.OpenForms["Book"];
newform.Close();

I am getting this error " 'System.Windows.Forms.Application' does not contain a definition for 'OpenForms' ".I checked in Application form and this OpenForms is not available.May i know the equivalent fix of OpenForms in compact framework or please provide me an alternative solution. 我收到此错误“ 'System.Windows.Forms.Application' does not contain a definition for 'OpenForms' ”。我在“应用程序”表单中签入,此OpenForms不可用。我可以知道紧凑框架中OpenForms的等效修复程序还是请为我提供替代解决方案。

Thanks 谢谢

There is no equivalent. 没有对等的东西。 The Compact Framework is compact because it doesn't include a lot of stuff that isn't needed. 紧凑框架之所以紧凑,是因为它不包含很多不需要的东西。 If you need to access a form later then keep a reference to it when you create it, which is what you should generally be doing in an application targeted at the full Framework anyway. 如果以后需要访问表单,则在创建表单时保留对其的引用,这通常是在针对完整框架的应用程序中通常应该执行的操作。

You don't necessarily have to create a class that tracks all forms, as is done in the link provided by Blogbeard. 您不必一定要创建一个跟踪所有表单的类,就像在Blogbeard提供的链接中所做的那样。 If this is just a one-off then just keep that one reference. 如果这只是一次,那么请保留该参考。 If you need to do it lots for various forms, then a centralised form manager may be a better option. 如果您需要为各种表单做很多事情,那么集中式表单管理器可能是一个更好的选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM