Results 1 to 27 of 27

Thread: how to close form1 when i open form2?

Hybrid View

  1. #1
    Hyperactive Member
    Join Date
    Dec 2006
    Location
    Ubuntu Haters Club
    Posts
    405

    Re: how to close form1 when i open form2?

    Quote Originally Posted by fifo
    Oh, no

    I did follow your code But I got a error, you can see in my attach Image.
    According to some tutorials that is the preferred method.

    I got the same error as you.

    Try digging into your mind
    » Twitter: @rudi_visser : Website: www.rudiv.se «

    If Apple fixes security flaws, they are heralded as proactive. If Microsoft fixes a security flaw, they finally got around to fixing their buggy OS.

  2. #2
    Frenzied Member tr333's Avatar
    Join Date
    Nov 2004
    Location
    /dev/st0
    Posts
    1,605

    Re: how to close form1 when i open form2?

    read this: http://vbforums.com/showthread.php?t=313050
    its written for vb.net, but the ideas are the same...

    basically you want to declare the reference to the new form as a public variable, something which cannot be done inside a method.

    Code:
    public Form newform = null;
    
    public static void Main() {
    ...
    then you can use the code that was first posted (slightly modified):

    Code:
    // newform has already been declared as a public variable
    newform = new Form2();
    newform.Show();
    this.Close();
    since the new form is no longer a child of the loginform, it won't disappear when the loginform is closed.
    CSS layout comes in to the 21st century with flexbox!
    Just another Perl hacker,

  3. #3
    Hyperactive Member
    Join Date
    Dec 2006
    Location
    Ubuntu Haters Club
    Posts
    405

    Re: how to close form1 when i open form2?

    Quote Originally Posted by tr333
    read this: http://vbforums.com/showthread.php?t=313050
    its written for vb.net, but the ideas are the same...

    basically you want to declare the reference to the new form as a public variable, something which cannot be done inside a method.

    Code:
    public Form newform = null;
    
    public static void Main() {
    ...
    then you can use the code that was first posted (slightly modified):

    Code:
    // newform has already been declared as a public variable
    newform = new Form2();
    newform.Show();
    this.Close();
    since the new form is no longer a child of the loginform, it won't disappear when the loginform is closed.


    I've tried placing a public declaration of a form EVERYWHERE, and it just doesn't work.

    I've put it in a class, before a class, before main, and got a million errors.

    It works when I put it in a class, however because I have to recreate the class in the form, it closes that form and the current form also:
    VB Code:
    1. class variables
    2.     {
    3.         public string windowsuser;
    4.         public mainos osform = new mainos();
    5.     }

    In form1:
    VB Code:
    1. timer4.Enabled = false;
    2.             vars.osform = new mainos();
    3.             vars.osform.Show();
    4.             this.Close();
    » Twitter: @rudi_visser : Website: www.rudiv.se «

    If Apple fixes security flaws, they are heralded as proactive. If Microsoft fixes a security flaw, they finally got around to fixing their buggy OS.

  4. #4
    Frenzied Member tr333's Avatar
    Join Date
    Nov 2004
    Location
    /dev/st0
    Posts
    1,605

    Re: how to close form1 when i open form2?

    i looked at one of my old projects as to how i did this, and it was surprisingly simple...

    Code:
    public System.Windows.Forms.Form LoginForm = new frmLogin // create new login form
    public System.Windows.Forms.Form MainForm; // don't create yet
    
    public static void Main() {
        MainForm = new frmMain; // create new main form
        Application.Run(LoginForm);
        Application.Run(MainForm);
        Application.Exit();
    }
    CSS layout comes in to the 21st century with flexbox!
    Just another Perl hacker,

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