Connecting Tech Pros Worldwide Forums | Help | Site Map

How to close a form?

Member
 
Join Date: Sep 2009
Location: Sunvillage
Posts: 42
#1: Sep 12 '09
Hi! I am creating a application for Windows Mobile using C#.
I am a new guy in Windows Mobile.
I am facing a problen.
I have 3forms.
on the form 2 I code on click of back menu.
Expand|Select|Wrap|Line Numbers
  1. form1 frm=new form1;
  2. form2 frm2=new form;
  3. frm2.close();
  4. frm1.show();
  5.  
the program is running without any error.
The form 1 is also displayed and form 2 get hide.
But when I close the form 1(Mean directly close from the title bar) it again show the form2.
Why don't the form2 is closing permanently with the frm2.close();
method. Is there any othe method for this?
Plz tell me.

Plater's Avatar
Moderator
 
Join Date: Apr 2007
Location: New England
Posts: 7,161
#2: Sep 15 '09

re: How to close a form?


Form2 isn't closing because you are making a NEW form2 right before it.
I think you are going to need to read up on Object Oriented Programming (OOP), it will probably help you furthor down the line
Member
 
Join Date: Sep 2009
Location: Sunvillage
Posts: 42
#3: Sep 21 '09

re: How to close a form?


I know this but the question is How can I close the form2. without anobject it doesn't have any mathod like close();
Plater's Avatar
Moderator
 
Join Date: Apr 2007
Location: New England
Posts: 7,161
#4: Sep 21 '09

re: How to close a form?


You will need to get an object for the form2 that is open.
If you are IN form2 when you want to close it, try calling this.Close()
Member
 
Join Date: Sep 2009
Location: Sunvillage
Posts: 42
#5: Sep 22 '09

re: How to close a form?


Yeh it will work while I am in form 2 but I want to close form2 from any other form.
Suppose from form3 on any button's click. How will I do this?
Plater's Avatar
Moderator
 
Join Date: Apr 2007
Location: New England
Posts: 7,161
#6: Sep 22 '09

re: How to close a form?


Hmm, you need publicly available references to the object.
How you do it is sort of up to you, you could cycle through Application.OpenForms[] and find the right one to close, or keep a public static object(s) somewhere that have references to them
Reply