windows form close and open next form

  • Thread starter Thread starter Sudha Pune
  • Start date Start date
S

Sudha Pune

Hi all

Just i want to close the form1 when i click the button1 on form1 and
the same time i want to load the form2 on the same event.


And i dont want to hide the form1 instead of close. Please post some
piece of coding

For the above i am using c# windows forms

Thanks
 
Sudha,


The first thing you need to do is open Form2 BEFORE closing Form 1

Just create a new instance and show it:
Frm2 = new Form2()
Frm2.Show();


You can then call Close(), or close form 1 from the Load event of Form 2;


Paul Cheetham
 
Hi paul

Thanks for ur reply,

If i close the form1 after opening the form2 then both forms are
getting closed

in the second way,
how will i get form1 reference on form2, i am able to create new form1
in form2, but i dont have any idea to get the existing form1 reference
on form2, can u tell me

please solve this issue

Thanks
 
If i close the form1 after opening the form2 then both forms are
getting closed

If form1 is your main form (i.e. the form displayed when your application
starts) then closing that form will, by default, close your application. I
believe it is possible to change this behaviour using the ApplicationContext
class, but I don't know the details - maybe someone else can help?

Chris Jobson
 
If i close the form1 after opening the form2 then both forms are
getting closed

If form1 is your main form (i.e. the form displayed when your application
starts) then closing that form will, by default, close your application. I
believe it is possible to change this behaviour using the ApplicationContext
class, but I don't know the details - maybe someone else can help?

Chris Jobson
 
The best way to do this is use MDIParent form and control all sub-forms from
that. Make the sub-forms fill the whole frame area.

form1.Close()
form2 = new Form2()
form2.ControlBox = false;
form2.Dock = DockStyle.Fill
form2.Show()
 
Back
Top