开封表格与主表格有所不同 [英] Opening Form Diffrent to main Form

查看:90
本文介绍了开封表格与主表格有所不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,我有一个问题,当我关闭Form1(我的打开表单)时,所有其他表单都关闭了.

如何设置它,以便Form2是关闭后将其全部关闭的窗体,但是我仍然希望Form 1在项目开始时运行.
我正在使用Visual Studio 2010

谢谢

Hey I have the problem that when I close Form1 (my opening form) all the other forms close down.

How do I set it so that Form2 is the form that when closed, closes all of them down, however I still want Form 1 to run at the begining of the project.
I''m using visual studio 2010

Thanks

推荐答案

这可能有所帮助,但由于您的问题措辞不佳,我不能保证任何事情.

C#Apps中的多个后续主"表单 [ ^ ]
This might help, but I''m not guaranteeing anything because your question is poorly worded.

Multiple Subsequent "Main" Forms in C# Apps[^]


您无法以简单的方式完成此操作,因为-看您的入口点("main"):应用程序运行是用您的表单调用的;定义哪种形式是主要的.它的实例作为静态只读(重要!)属性Application.MainForm返回.没有API可以切换主要形式-有充分的理由!

我最好的信念:您不应该这样做,因为它会使您的用户非常困惑.

不过,如果您像我一样疯狂,并且想解决此限制,则可以执行此操作!你应该

1)关闭主窗体并退出应用程序循环.

2)现在,您需要使用不同的参数(您不同的形式)再次调用Application.Run.您应该了解,它可能需要关闭并重新打开您不同的表单,然后您可能需要存储(持久化)并完全恢复其状态.您需要在main方法中编写此代码.

3)您可能希望将此呼叫作为条件呼叫,否则您将看不到

4)您可能会在主窗体中查找Application.Run,将主窗体的大小写切换为大小写.

5)您应该提供一个选项,以允许用户完全关闭应用程序",因为考虑到第(4)项,您可以永远运行它.例如,这可以在菜单项退出"中完成,因为关闭表单不再支持应用程序的完全终止.您将需要一个静态条件数据字段(仅因为您的main是静态的).

我是出于好奇而做到的.

现在,您需要说我不需要"并接受我的回答,或者使用我的计划编写代码. (可选)如果您说服我欢迎您这样做(最好是在您付出一些努力之后),我会很乐意编写此代码.在所有情况下,我都同意回答合理的后续问题.

Again, I do not recommend doing it for real-life application!
You cannot do it in a simple way, because -- look at your entry point ("main"): Application Run is called with your form; that defines which form is main. Its instance is returned as the static read-only (important!) property Application.MainForm. There is no API to switch the main form -- for a good reason!

My best believe: you should not do this, because it will confuse your user very well.

Nevertheless, if you''re as crazy as I am and want to work around this limitation, you can do this! You should

1) Close your main form and go out of application loop.

2) Now, you need to call Application.Run again with different parameter (your different form). You should understand that it may require your different form to be closed and re-opened, then you may need to store (persist it) and completely restore its state. You need to write this code in your main method.

3) You may want to make this call conditional, otherwise you will not see

4) You may look Application.Run within your main, switching main form case to case.

5) You should provide an option to allow the user to "close application completely", because, considering item (4), you may run it forever. This can be done in menu item "Exit", for example, as closing a form is no longer supports complete termination of the application. You will need a static condition data field (only because your main is static).

I did it, out of curiosity.

Now, you need either to say "I don''t need it" and accept my answer or write a code using my plan. Optionally, I would gladly write this code, if you convince me that this effort is welcome (better after you show some of your effort). In all cases, I agree to answer reasonable follow-up questions.

Again, I do not recommend doing it for real-life application!


可能和在Form1的初始化中显示Form2一样简单,然后隐藏Form1直到Form2关闭?

这是一个肮脏的示例:
Possibly something as simple as showing Form2 from with Form1''s initialization, then hiding Form1 until Form2 closes?

Here''s a dirty sample:
public partial class Form1 : Form
{
    public Form2 frm2 = new Form2();
    public Form1()
    {
        InitializeComponent();
        Hide();
        frm2.ShowDialog();
        Show();
    }
}



直到Form2关闭,Form1才有机会被看到.



Form1 doesn''t get a chance to be seen until Form2 closes.


这篇关于开封表格与主表格有所不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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