how do i pass control from one window to another?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rotaryfreak
    New Member
    • Oct 2008
    • 74

    how do i pass control from one window to another?

    Hi all,

    I'm fairly new to c# and im trying to create a windows form application made up of 3 pages. The first, a login page, the second, a search page, and the third will be a page to fill in some fields to save the info to a database.

    My problem is that i can not manage to transfer control from one page to another, that is, when the program launches, i can not get it so that it directs control to the login and then the use presses the login button, they are displayed the second page, which is the search page.

    After having coded in java for a few years, i know that if this were a java application, all i would have to do is set the current thread of control to a frame and dispose of the previous frame, if you wish. My troubles in C# is that in using Web Forms, i can not seem to transfer control from one .cs file to another.

    this is what i have tried:
    By default, the windows forms creates a Form1.cs which is the entry point of the program. In the Form1() where it is supposed to call initiate(), i changed that to call my own login class:


    Code:
    public Form1()
            {
                InitializeComponent()
            }
    i changed to this, expecting that my login page would pop up:

    Code:
    public Form1()
            {
                
                new Login();
            }
    when i do this, my login page does not come up, instead, a blank window comes up.

    So, my question is the following:

    how to do i create my application so that the entry point is through Form1, but then call Login() and my subsequent pages?

    thanks, any guidance will be much appreciated.
  • adriancs
    New Member
    • Apr 2011
    • 122

    #2
    Code:
    public Form1()
    {
         InitializeComponent()
         Login f = new Login();
         f.ShowDialog();
    }

    Comment

    • rotaryfreak
      New Member
      • Oct 2008
      • 74

      #3
      Thank you very much! it worked like a charm!

      Comment

      • bvrwoo
        New Member
        • Aug 2011
        • 16

        #4
        Also, if you want your Login to change when you are in another form and click for response, you can pass a delegate to the login to pick it up and change automatically. Make use of C# type function pointers (delegates) which I still prefer C/C++ for pointers any day of the week but .NET has a lot to offer to make your programming easier.

        Comment

        Working...