自动在C#中隐藏当前表单,然后显示另一个表单 [英] automaticly hide current form in c# and then show another form

查看:88
本文介绍了自动在C#中隐藏当前表单,然后显示另一个表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在几秒钟后隐藏当前表单,然后显示任何表单

我正在编写此代码,但不起作用.

I need to hide current form after many second and then show any form

I''m writing this code but it doesn''t work.

namespace tempprj
{
    public partial class ProfileFrm : Telerik.WinControls.UI.RadForm
    {
       public ProfileFrm()
       {
           InitializeComponent();
       }

       private void ProfileFrm_Load(object sender, EventArgs e)
       {
            Frm2 child = new Frm2();
            Thread.Sleep(3000);
            this.Hide();
            child.ShowDialog();
       }
   }
}

推荐答案

请不要告诉我们事情不起作用.它怎么不起作用?它有什么作用 ?除非您有理由保留此表格但将其隐藏起来,否则最好的选择是不要这样做.创建您的主表单,并将其保留在内存中,并显示子表单.如果要显示初始屏幕,请在构造函数中显示它,以便立即显示它,并在表单首次显示时在事件中将其隐藏.
Please don''t tell us that things don''t work. How doesn''t it work ? What does it do ? Unless you have a reason for this form to stay in memory, but be hidden, your best bet is to not do this. Create your main form, and keep it in memory, showing child forms. If you want to show a splash screen, show it in your constructor, so it''s shown right away, and hide it in the event when your form first becomes visible.


此解决方案可能不是最优雅的,但是我认为它应该可以达到目的.

This solution might not be the most elegant one, but I think it should work for this purpose.

using WinFormsTimer = System.Windows.Forms.Timer;

namespace Test
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            // Define a timer which fires a tick event after 1 second
            WinFormsTimer timer1              = new WinFormsTimer();
            timer1.Interval                   = 1000;
            timer1.Enabled                    = true;
            timer1.Tick                      += timer1_Tick;
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            // Display another form
            Form2 form2 = new Form2();
            form2.Show();

            // Stop the timer to prevent the creation of additional forms
            WinFormsTimer timer1 = sender as WinFormsTimer;
            timer1.Stop();
        }
    }
}


我认为您需要这个:

I think you need this:

private void ShowForm() where T: Form, new()
{
    T form = new T();

    form.FormClosed += delegate(object sender, FormClosedEventArgs e)
    {
        this.Show();
    };

    this.Hide();
    form.Show();
}







private void childButton_Click(object sender, EventArgs e)
{
    ShowForm<child>();
}



让我知道这是否不是您的想法.



Let me know if it is not what you thought.


这篇关于自动在C#中隐藏当前表单,然后显示另一个表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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