Results 1 to 9 of 9

Thread: C# Forms Help

  1. #1
    Join Date
    Dec 2005
    Posts
    1,951
    Rep Power
    0

    Default C# Forms Help

    After the user inputs idnum and password. If thats correct the loginwindow is suppose to minimize and the mainwindow is suppose to come up. The main window comes up but the login window wont go away.

    login window



    main window


    my problem


    Code:
    if (userName_login_window.Equals("1") && pass_login_window.Equals("2"))
              {
                 
                  MainWindow window = new MainWindow();
                  window.ShowDialog();//Brings up the main window
                  Application.Exit();//suppose to close login window but doesnt work.
                  
                  
                  
              }

    HELP Greatly needed.
    Last edited by mobile_fan_2k5; May 16, 2010 at 04:00 PM.
    Pc= Hp dv6t

  2. #2
    Join Date
    Jan 2009
    Posts
    2,404
    Rep Power
    0

    Default

    Did you try setting the login window's Visible property to False?
    Rooted OnePlus 2 64GB Ed, Android 5.1.1 OxygenOS ; on teifin' AT&T's network; Rooted ASUS Transformer TF101 w/ dock, Android 5.1 KatKiss; Laptop: ASUS X550C, 2.0GHzx2, 8GB, 512GB SSD, Kubuntu 15.10;
    Facebook page: Skeleville Technology Solutions

  3. #3
    Join Date
    Dec 2005
    Posts
    1,951
    Rep Power
    0

    Default

    I placed the following code in the if statement after the main windows is supposed to come up, but it still didnt work.
    LoginWindow login = new LoginWindow();
    login.Visible = false;
    Remember the login window should be initially visible and running, then after the user inputs idnum and password, then the main window comes up. After the main comes up the login window would be sitting there taking up space. I want to hide. Since i just found out it cant be close because its the default form.
    Last edited by mobile_fan_2k5; May 16, 2010 at 09:31 PM.
    Pc= Hp dv6t

  4. #4
    Join Date
    Jan 2009
    Posts
    2,404
    Rep Power
    0

    Default

    Ah yes. I'm definitely seeing your foul up now. If the login window is your main form, then when you close it, the app closes (don't see why hiding it doesn't work though). You put the main window as a child of the login window, so the Application.Exit(); statement won't be executed until you close the main window. It should be the other way around, then use the OnLoad event (or similar) to load that login window.

    EDIT:
    Code:
    LoginWindow login = new LoginWindow();
    login.Visible = false;
    This won't work the way how you expected it. For one, you just created the object, you didn't even ShowDialog() it in the first place, yet you're hiding it. Also, the Visible = False; isn't needed once you validate the password and the login window closes.
    Last edited by Skele Drew; May 17, 2010 at 06:51 AM.
    Rooted OnePlus 2 64GB Ed, Android 5.1.1 OxygenOS ; on teifin' AT&T's network; Rooted ASUS Transformer TF101 w/ dock, Android 5.1 KatKiss; Laptop: ASUS X550C, 2.0GHzx2, 8GB, 512GB SSD, Kubuntu 15.10;
    Facebook page: Skeleville Technology Solutions

  5. #5
    Join Date
    Dec 2005
    Posts
    1,951
    Rep Power
    0

    Default

    the answer was staring in front of me all this time, its so simply.
    if (userName_login_window.Equals("1") && pass_login_window.Equals("2"))
    {
    MainWindow window = new MainWindow();
    this.Hide();
    window.ShowDialog();
    }
    the this.Hide(); would be executed before the window.showDialog(); and just like that what seemed so hard just flow.
    Pc= Hp dv6t

  6. #6
    Join Date
    Jan 2009
    Posts
    2,404
    Rep Power
    0

    Default

    That will work. But I still don't get why you're still using the login as the main window and creating the main window as a child of the login window. Seems like a minor resource mismanagement since you're only using the login window once (it's still taking up memory when it's hidden). This style can also lead to more expansion problems later...
    Rooted OnePlus 2 64GB Ed, Android 5.1.1 OxygenOS ; on teifin' AT&T's network; Rooted ASUS Transformer TF101 w/ dock, Android 5.1 KatKiss; Laptop: ASUS X550C, 2.0GHzx2, 8GB, 512GB SSD, Kubuntu 15.10;
    Facebook page: Skeleville Technology Solutions

  7. #7
    Join Date
    Dec 2005
    Posts
    1,951
    Rep Power
    0

    Default

    I figured out that much, but i making the app first then fixing problems later. Kinda like microsoft.
    Pc= Hp dv6t

  8. #8
    Join Date
    Nov 2002
    Posts
    2,832
    Rep Power
    0

    Default

    Why are u hiding the login window? That's a waste of resource for a form that isn't gonna be used anymore.

    Change your code to this:

    if (userName_login_window.Equals("1") && pass_login_window.Equals("2"))
    {
    MainWindow window = new MainWindow();
    window.Show(); // no need to use ShowDialog()
    this.dispose(); //results in the CLR executing the necessary garbage collection to reclaim resources

    }
    Device: iPhone® 4S OS: v5
    POWERED By: LIME 3G


  9. #9
    Join Date
    Dec 2005
    Posts
    1,951
    Rep Power
    0

    Default

    @seanbee20, thanks for the advice. I'll have to take resource management into consideration, not everyone have 4gb of ram to pour kbs or mbs of space to run apps.
    Pc= Hp dv6t

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •