how to close a form at runtime in a window application

Posted on 2008-11-20
Last Modified: 2012-05-05
Hi experts,

my question is that As i click ona button the following should be happen

1.a form should be open that .this form will be there for almost 3-4 second on screen after this ,that form will be closed.
2. As it close a new form will be opened.

how could we done it in c# window applicatiopn.

Please let me know about it ASAP.
Question by:ASINGH1974
    LVL 2

    Expert Comment

    it;s a problem if it's made in delphi?

    Author Comment

    actually i want this functionality in c#, window application
    LVL 22

    Expert Comment

    Just so i understand, for example:

    from Form1, you press a button
    that opens Form2, which lingers for 4 seconds
    when it closes, it launches Form3?

    Author Comment

    yes, you are saying right.
    i want this type of functionality
    LVL 22

    Accepted Solution

    Okay, should be done the easiest with a timer.
    In Form1 on the button click, launch Form2 as you would any other:

    private void button1_Click(object sender, EventArgs e)
        new Form2().Show();

    Then in add an event for the Form2 Load in it's code behind, and hook up as follows:

    private void Form2_Load(object sender, EventArgs e)
        //create a timer for the 4 second delay and wire up and event handler for the tick event
        Timer t = new Timer();
        t.Interval = 4000;
        t.Tick += new EventHandler(Timer_Tick);
    protected void Timer_Tick(object sender, EventArgs e)
        //on the tick event, kill the timer, make this form invisible, launch the 3rd form, and then close this one
        this.Visible = false;
        new Form3().Show();

    Author Closing Comment


    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Join & Write a Comment

    Article by: Ivo
    Anonymous Types in C# by Ivo Stoykov Anonymous Types are useful when  we do not need to follow usual work-flow -- creating object of some type, assign some read-only values and then doing something with them. Instead we can encapsulate this read…
    Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now