How to close a form?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Kapil Choubisa
    New Member
    • Sep 2009
    • 47

    How to close a form?

    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.
    Code:
    form1 frm=new form1;
    form2 frm2=new form;
    frm2.close();
    frm1.show();
    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
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    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

    Comment

    • Kapil Choubisa
      New Member
      • Sep 2009
      • 47

      #3
      I know this but the question is How can I close the form2. without anobject it doesn't have any mathod like close();

      Comment

      • Plater
        Recognized Expert Expert
        • Apr 2007
        • 7872

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

        Comment

        • Kapil Choubisa
          New Member
          • Sep 2009
          • 47

          #5
          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?

          Comment

          • Plater
            Recognized Expert Expert
            • Apr 2007
            • 7872

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

            Comment

            Working...