Click here to Skip to main content
16,018,418 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I need to hide current form after many second and then show any form

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

C#
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();
       }
   }
}
Posted
Updated 2-Aug-12 11:06am
v2
Comments
Dave Kreskowiak 2-Aug-12 17:04pm    
Are you trying to make a splash screen or seomthing to that effect??
[no name] 2-Aug-12 17:11pm    
Do you want to hide the form while child has shown?
Sergey Alexandrovich Kryukov 2-Aug-12 17:18pm    
Why? Would be too confusing to the users.
--SA

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.
 
Share this answer
 
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();
        }
    }
}
 
Share this answer
 
I think you need this:

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

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

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



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


Let me know if it is not what you thought.
 
Share this answer
 
v3
Hi! I think the following code will help you. All you need to do is to use a
ProgressBar and Timer.

C#
private void timer1_Tick(object sender, EventArgs e)
{
    progressbar1_Loading.Value += 2;
    if (progressbar1_Loading.Value == 100)
    {
        Form2 form = new Form2();
        form.Show();
        this.Visible = false;
        timer1.Stop();
    }
}
private void Form1_Load(object sender, EventArgs e)
{
    timer1.Start();
}

So, when progressbar value will be 100 the form2 will load automatically.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900