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();