How to navigate from one form to another form in C# in a windows application?

Posted on 2007-03-21
Last Modified: 2008-01-09
I have a windows based application with 2 forms Login.cs and welcome.cs built in MS Visual Studio.Net  2003. I have a button in the Login page that user will click and it should bring the user to the welcome page and close the login page. I would like to know the C# code that will briing you go to another page after clicking the button.  An example of code will be very helpful. Thanks!
Question by:cepproducer
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Accepted Solution

badbearontour earned 45 total points
ID: 18763923


The following should do it:
btnLogin_click(......) // this is the button click handler on your login form
   welcome myWelcomeForm = new welcome();;


Author Comment

ID: 18763992
Thank you! This works fine but how about closing the login windows?

Assisted Solution

zajda82 earned 40 total points
ID: 18764065
Show the window modally

MyWindow w = new MyWindow(); // login window
if(w.ShowDialog() == DialogResult.OK)
// login window closed with OK result
WelcomeWindow ww = new WelcomeWindow(); // welcome window
Stressed Out?

Watch some penguins on the livecam!


Author Comment

ID: 18764210
Hi zajda82:

    i tried your code but the new windows that come out is still the login page and the original login page also wasn't close automatically. Can you help?

Expert Comment

ID: 18764482
show me some code of how are you doing that
LVL 86

Assisted Solution

by:Mike Tomlinson
Mike Tomlinson earned 40 total points
ID: 18766488
Use main() in Program.cs to show your Login form.  Then only use Application.Run() if login was actually successful...

    static class Program
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main()
            Login lgn = new Login();
            if (lgn.ShowDialog() == DialogResult.OK)
                Application.Run(new welcome());

Featured Post

Is Your Team Achieving Their Full Potential?

74% of employees feel they are not achieving their full potential. With Linux Academy, not only will you strengthen your team's core competencies but also their knowledge of of the newest IT topics.

With new material every week, we'll make sure that you stay ahead of the game.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

688 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