表格显示/隐藏问题 [英] Form Show / hide problem

查看:93
本文介绍了表格显示/隐藏问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在win窗体应用程序中,我有2个窗体(form1,form2):
在form1中,我有:

In win forms application ,I have 2 forms (form1,form2):
In form1 I have :

this.hide();
Form2.Show();


现在在form2中,我想显示以前的形式,而不是通过实例化
如何访问form1?

表格2:


Now in form2 I want to show the previous form ,not by instancing
How can I access form1?

Form2:

this.hide();
//how can I show the first form ,Not by Instance a new !

推荐答案

每次显示或隐藏表单时,都可以在新的FormManager.cs文件中创建静态类.
示例:

You can make a static class in a new FormManager.cs file, every time you show or hide a form use this class.
Example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WindowsFormsApplication1
{
    public class FormManager
    {
        static FormManager _instance = null;
        private Form1 f1 = new Form1();
private Form2 f2 = new Form2();
        public static FormManager Instance
        {
            get
            {
                if (_instance == null)
                    _instance = new FormManager();

                return _instance;
            }
        }

        public void FormOne(bool flag)
        {
            if (flag == true)
                f1.Show();
            else
                f1.Hide();
        }

public void FormTwo(bool flag)
        {
            if (flag == true)
                f2.Show();
            else
                f2.Hide();
        }
    }
}


形式的示例代码


Sample code of the form

FormManager.Instance.FormOne(true);


有很多方法可以做到这一点
但是方式取决于需求/应用.

1.您可以在Form2中使用Form1的引用
2.您可以将Form2打开为DialogBox
3.您可以利用启动类来管理应打开的表单.
等等


我建议您多说一些您的问题

谢谢
There are number of ways of doing this
but way is depend on requirement/application.

1. You can use reference of Form1 in Form2
2. You can open Form2 as DialogBox
3. you can make use of start up class to manage which form should be open.
and so on


I suggest you to say more about your question

Thanks


,格式为1
你写

form2.ShowDialog();

然后在form2之后

form2.close();





表单在form1中声明为一个静态类
in the form1
you write

form2.ShowDialog();

then after in form2

form2.close();



or

form declare as one static class in form1


这篇关于表格显示/隐藏问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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