Click here to Skip to main content
15,908,768 members
Home / Discussions / C#
   

C#

 
AnswerRe: Application.Exit(); not working in the form constructor, why? Pin
Nader Elshehabi24-Oct-06 15:22
Nader Elshehabi24-Oct-06 15:22 
GeneralRe: Application.Exit(); not working in the form constructor, why? Pin
AngryC24-Oct-06 16:31
AngryC24-Oct-06 16:31 
GeneralRe: Application.Exit(); not working in the form constructor, why? Pin
EricT.25-Nov-10 7:27
EricT.25-Nov-10 7:27 
QuestionSearch for statements in CS files. Pin
Alex Iagovsky24-Oct-06 14:34
Alex Iagovsky24-Oct-06 14:34 
AnswerRe: Search for statements in CS files. Pin
Nader Elshehabi24-Oct-06 15:29
Nader Elshehabi24-Oct-06 15:29 
GeneralRe: Search for statements in CS files. Pin
Alex Iagovsky25-Oct-06 3:19
Alex Iagovsky25-Oct-06 3:19 
QuestionForms Pin
m.m._200724-Oct-06 14:07
m.m._200724-Oct-06 14:07 
AnswerRe: Forms [modified] Pin
Nader Elshehabi24-Oct-06 15:40
Nader Elshehabi24-Oct-06 15:40 
Hello

I don't know why someone flamed you with score 1.0, and didn't even answer you -wasn't me btw-. Your question is quite very simple -forgive me for saying that-. I guess you didn't do much reading in OOP did you?;)

The first block of code is fine in creating a form, while the second is far from closing one:
m.m._2007 wrote:
Form1 form1 = new Form1();

The above line creates a new form of type Form1. So refereing to it would be to the new form not your original form.
m.m._2007 wrote:
form2.Show();

And this line shows the new form that you've just made in the previous block. Why on earth did you expect it to close the original one? Shouldn't you've called the method Close() at least?

To make your code work you have to pass reference to your original form to the Form2 object and call the Close() method for it.

Edit your Form2 constructor to
private Form1 orgigenal
Form2(Form1 or)
{
    origenal = or;
    //More code
}

Now show Form2 like this:
Form2 myForm = new Form2(this);// referencing to the original form

and in Form2 close Form1 like this
origenal.Close();


I hope you got it, and I strongly suggest you do more reading in C# OOP programming.




-- modified at 21:59 Tuesday 24th October, 2006

RegardsRose | [Rose]

AnswerRe: Forms Pin
phenix-burn24-Oct-06 15:42
phenix-burn24-Oct-06 15:42 
QuestionSocket class Poll method and POP3 client Pin
Martin Lachowicz24-Oct-06 13:00
Martin Lachowicz24-Oct-06 13:00 
QuestionCounting months between dates? Pin
rbaut24-Oct-06 12:08
rbaut24-Oct-06 12:08 
AnswerRe: Counting months between dates? Pin
Guffa24-Oct-06 12:15
Guffa24-Oct-06 12:15 
QuestionWhy doesn't the left mouse button work... [modified] Pin
new_phoenix24-Oct-06 11:19
new_phoenix24-Oct-06 11:19 
QuestionCollectionEditor and Generics Pin
Jamie Nordmeyer24-Oct-06 10:43
Jamie Nordmeyer24-Oct-06 10:43 
QuestionNeed to access value from app.config file Pin
Shilpa124-Oct-06 10:21
Shilpa124-Oct-06 10:21 
AnswerRe: Need to access value from app.config file Pin
Craig G Fraser24-Oct-06 20:39
Craig G Fraser24-Oct-06 20:39 
Questionrandom numbers Pin
Jad Jadallah24-Oct-06 10:18
Jad Jadallah24-Oct-06 10:18 
AnswerRe: random numbers Pin
Jim Conigliaro24-Oct-06 10:53
Jim Conigliaro24-Oct-06 10:53 
GeneralRe: random numbers Pin
Jad Jadallah24-Oct-06 11:13
Jad Jadallah24-Oct-06 11:13 
AnswerRe: random numbers Pin
Guffa24-Oct-06 12:10
Guffa24-Oct-06 12:10 
GeneralRe: random numbers Pin
Jad Jadallah24-Oct-06 12:24
Jad Jadallah24-Oct-06 12:24 
AnswerRe: random numbers Pin
Guffa24-Oct-06 13:11
Guffa24-Oct-06 13:11 
AnswerRe: random numbers Pin
Guffa25-Oct-06 7:44
Guffa25-Oct-06 7:44 
GeneralRe: random numbers Pin
Jad Jadallah25-Oct-06 8:44
Jad Jadallah25-Oct-06 8:44 
Questiondelete files from a directory Pin
keroed_edmond24-Oct-06 10:18
keroed_edmond24-Oct-06 10:18 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.