Solved

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

Posted on 2007-03-21
6
1,368 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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

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

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

Suggested Solutions

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

760 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

18 Experts available now in Live!

Get 1:1 Help Now