|
-
Dec 15th, 2006, 05:02 AM
#1
Hyperactive Member
Re: how to close form1 when i open form2?
 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.
-
Dec 15th, 2006, 09:58 AM
#2
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.
-
Dec 15th, 2006, 03:21 PM
#3
Hyperactive Member
Re: how to close form1 when i open form2?
 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:
class variables
{
public string windowsuser;
public mainos osform = new mainos();
}
In form1:
VB Code:
timer4.Enabled = false;
vars.osform = new mainos();
vars.osform.Show();
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.
-
Dec 17th, 2006, 06:21 PM
#4
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();
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|