Solved

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

Posted on 2007-03-21
6
1,374 Views
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!
0
Comment
Question by:cepproducer
6 Comments
 
LVL 7

Accepted Solution

by:
badbearontour earned 45 total points
ID: 18763923

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
 

Author Comment

by:cepproducer
ID: 18763992
Thank you! This works fine but how about closing the login windows?
0
 
LVL 3

Assisted Solution

by:zajda82
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
ww.Show();
}
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Author Comment

by:cepproducer
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?
0
 
LVL 3

Expert Comment

by:zajda82
ID: 18764482
show me some code of how are you doing that
0
 
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>
        [STAThread]
        static void Main()
        {
            Login lgn = new Login();
            if (lgn.ShowDialog() == DialogResult.OK)
            {
                Application.Run(new welcome());
            }
        }
    }
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
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…

821 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