• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1434
  • Last Modified:

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

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!
0
cepproducer
Asked:
cepproducer
3 Solutions
 
badbearontourCommented:

Hi

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


BB
0
 
cepproducerAuthor Commented:
Thank you! This works fine but how about closing the login windows?
0
 
zajda82Commented:
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
ww.Show();
}
0
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 
cepproducerAuthor Commented:
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?
0
 
zajda82Commented:
show me some code of how are you doing that
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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>
        [STAThread]
        static void Main()
        {
            Login lgn = new Login();
            if (lgn.ShowDialog() == DialogResult.OK)
            {
                Application.Run(new welcome());
            }
        }
    }
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now