Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
i have 2 form in form 1 i have a button when i click on button form 2 will be show and my data are showing on form 2 so far its OK but i want when one of form 2 its open if user click on button in form 1 then close this form 2 and open a new one! not open an other form 2 i hope u understand my question :D sorry for bad English

and here is button code :

    private void btnSave_Click(object sender, EventArgs e)
    {

            if (RadioMale.Checked == true)
            {
                jensiyat = "مرد";
            }
            else { jensiyat = "زن"; }
            if (RadioMarried.Checked == true)
                tahol = "متاهل";
            else tahol = "مجرد";
        Class1.txt +=
           "________________________\n\n" + "مشخصات مربوط به  خانم/آقای " 
           + tbFamily.Text + "\n________________________" +
            "\nنام و نام خانوادگی: " + tbName.Text + " " +
            tbFamily.Text + "\n" + "ایمیل: " + tbEmail.Text + "\n" + "شماره ملی: " +
            tbCodmeli.Text + "\n" + "سریال شناسنامه: " +
            tbSerialShenasname.Text
            + "\nشهر محل زندگی: "+ shahr + " - " + TreeShahr.SelectedNode.Text
            + "\nآدرس: " + tbAddress.Text + "\n"
            + " تحصیلات : " + ComboTahsilat.SelectedItem
            + "\nجنسیت : " +jensiyat
            + "\nوضعیت تاهل: " + tahol
            + "\nتاریخ تولد: " + BirthTimePicker.Value.ToPeString()
            + "\n__________________________________________________";

        Form frm2 = new Form2();
        frm2.Show();
    }


What I have tried:

i tried form instance function but its not working its just hold this form 2 and will not allow to open new one! with these code:

public static Form2 Instance
   {
       get
       {
           if (_form2 == null)
           {
               _form2 = new Form2();
           }
           return _form2;

       }
   }
Posted
Updated 9-Mar-17 22:56pm
v3
Comments
BillWoodruff 10-Mar-17 23:15pm    
Why do you want to create a new instance of Form2 rather than re-use one instance ?

What version C# and .NET FrameWork are you using ?
Member 13019612 13-Mar-17 18:11pm    
becoz i want to refresh form2
i use 4.5 .Net and 2013 visual studio

1 solution

I would suggest you look inside the Application.OpenForms-Collection if the Form2 is allready opened.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900