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

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

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
The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.


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 85

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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

840 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