Post: C# Code
08-31-2011, 10:39 AM #1
Pauly
Banned
(adsbygoogle = window.adsbygoogle || []).push({}); i am new to C# and i need the code to make a button open another form
Last edited by Pauly ; 08-31-2011 at 10:42 AM.

The following user groaned Pauly for this awful post:

CodingNation
09-13-2011, 04:21 AM #20
Epic?
Awe-Inspiring
Originally posted by BAdmaNgLiTcHa View Post
After looking back at this I realise I had made a mistake what I replied with was in-fact wrong.
I implemented for name to create a new form which was not the question asked which was to show a already made form.
The correct script is:
    Form name = new name();
name.show();

God sometimes I can make the silliest of mistakes. Enzo


Actually I think you may have had it right the first time. Let's say the form you are trying to open has already been created and is called "Form2", you would open a new instance of it like so:
    
Form2 frm = new Form2();
frm.Show();


You'd only do it your way if you were creating a whole new form, not a whole new instance of a pre-existing form.
09-13-2011, 02:40 PM #21
Woof
...hmm
Originally posted by AsianInvasion View Post
Actually I think you may have had it right the first time. Let's say the form you are trying to open has already been created and is called "Form2", you would open a new instance of it like so:
    
Form2 frm = new Form2();
frm.Show();


You'd only do it your way if you were creating a whole new form, not a whole new instance of a pre-existing form.


The correct turm to open an already made form is:

Form NGU = new name();
NGU.Show();

You need to set the value of the variable as a form, in this case the form is set to NGU.
Then you need to set what form it is to be set too, which in this case i have put name(acting as teh already made form)
Once done all you need to do is use NGU(the set variable of name) to show.
Last edited by Woof ; 09-13-2011 at 02:48 PM.
09-13-2011, 05:34 PM #22
Epic?
Awe-Inspiring
Originally posted by BAdmaNgLiTcHa View Post
The correct turm to open an already made form is:

Form NGU = new name();
NGU.Show();

You need to set the value of the variable as a form, in this case the form is set to NGU.
Then you need to set what form it is to be set too, which in this case i have put name(acting as teh already made form)
Once done all you need to do is use NGU(the set variable of name) to show.


Yes, I see what you're saying.

Let's say you have a form called "Form2" and you are opening it from Form1, any of these will work:
    
Form test = new Form2();
test.Show();

Form2 test1 = new Form2();
test1.Show();

var test2 = new Form2();
test2.Show();

You can try it out in your own project, just create a form called Form2.

The difference is in one you are created an object of type var, the other of type Form2, and the other of type Form. Creating one of Form2 would be preferred in this case, since you are indeed opening Form2 to begin with.
09-13-2011, 06:28 PM #23
Woof
...hmm
Originally posted by AsianInvasion View Post
Yes, I see what you're saying.

Let's say you have a form called "Form2" and you are opening it from Form1, any of these will work:
    
Form test = new Form2();
test.Show();

Form2 test1 = new Form2();
test1.Show();

var test2 = new Form2();
test2.Show();

You can try it out in your own project, just create a form called Form2.

The difference is in one you are created an object of type var, the other of type Form2, and the other of type Form. Creating one of Form2 would be preferred in this case, since you are indeed opening Form2 to begin with.


yea, I know.
You don't need to repost everything I say. :rolleyes:
09-13-2011, 08:38 PM #24
Epic?
Awe-Inspiring
Originally posted by BAdmaNgLiTcHa View Post
yea, I know.
You don't need to repost everything I say. :rolleyes:


Dude. I'm not reposting everything you said, you said that you had it wrong the first time, when you actually had it correct, I was correcting your incorrect correction. And that sentence probably made very little sense to anyone.
09-13-2011, 08:44 PM #25
Woof
...hmm
Originally posted by AsianInvasion View Post
Dude. I'm not reposting everything you said, you said that you had it wrong the first time, when you actually had it correct, I was correcting your incorrect correction. And that sentence probably made very little sense to anyone.


If you read what my reply actually was you will know I said to is correct in the way it would create a new form, which is not what is wanted in this question. Winky Winky
09-15-2011, 12:15 AM #26
Pichu
RIP PICHU.
Originally posted by Correy View Post
name.Show(); does not work, i know this cause i've tried it numerous amount of times when i first started C#


I think he was stating that you could use either or after the main Form.Name = new yada yada.

Copyright © 2024, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo