Results 1 to 8 of 8

Thread: load 2 forms

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2006
    Location
    /root/usr/local/bin
    Posts
    476

    load 2 forms

    hello!
    i want to load the frmMain then the frmLogin (showdialog)
    how could i do that?

    tnx

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: load 2 forms

    Handle the Shown event of your main form, create an instance of your login form and call its ShowDialog method.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2006
    Location
    /root/usr/local/bin
    Posts
    476

    Re: load 2 forms

    not working

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: load 2 forms

    Quote Originally Posted by basti42
    not working
    Gee, could you give any less information? What I suggested will do what you asked for. If it's not working then you're not doing it properly. If you don't show us or explain to us what you are doing then we can't help. Is that not common sense?
    Last edited by jmcilhinney; Apr 26th, 2007 at 10:47 PM.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2006
    Location
    /root/usr/local/bin
    Posts
    476

    Re: load 2 forms

    ok sorry...
    im am new to c# and obviously im not smart as you are

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: load 2 forms

    Like I said, it's common sense and nothing to do with C#. If you want a problem diagnosed you have to provide information, whatever it relates to. Would you expect a doctor to give you the right medicine if you went into their office and said "I'm sick"? Explain your situation. Show us the code you're using. Tell us what "not working" means? Is an exception thrown? Does your computer explode? Something else? We can't guess. You have to tell us. When you do then we can hopefully provide a solution.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2006
    Location
    /root/usr/local/bin
    Posts
    476

    Re: load 2 forms

    yeah your right it's a common sense but you must consider
    that's why im seeking for your help because i already searched through
    the net and im failed. for you it's simple because you know it's hard for
    me because i don't know simple as that.

    private void frmMain_Load(object sender, EventArgs e)
    {
    frmLogin fLogin = new frmLogin();
    fLogin.ShowDialog();
    }

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: load 2 forms

    That code will do what you asked for. I assume that your problem now is that the same thing happens whether the login is successful or not. If that's the case then that's what you should have said. Like I said, "doesn't work" doesn't really tell us much.

    When you display a form by calling its ShowDialog method you normally set its DialogResult property to dismiss it. The DialogResult property value indicates the result of the dialogue, e.g. OK, Cancel, etc. In your case you would set it to OK for a successful login and Cancel otherwise.

    That DialogResult value then gets returned by the ShowDialog method. That's how the caller is able to determine what happened and how to proceed. If ShowDialog returns OK you know the login was successful and you proceed accordingly.

    Note also that I said originally said handle the Shown event, not the Load event. Load is raised before the form is displayed, while Shown is raised after. You can handle either but your original question implied after. Note also that once the Load event is raised you can't stop the form being shown, so even if you try to close it it will flash on screen for a moment.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

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



Click Here to Expand Forum to Full Width