windows form close and open next form

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
 
P

Paul Cheetham

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
 
S

Sudha Pune

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
 
C

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
 
C

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
 
I

Ian Semmel

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top