Hey hi i am new to this field , i am working on project which is desktop application in C#,in the project there are three forms ,i want to show only working form and all other form should get close 'showdialogue' method also does not work ...............please give me some solution for this .

How you are going to open these 3 forms? Will you open 1 and then by clicking something on form1, this has to close and open form2, and so on?

1. You can simply use hide() method for the form you want NOT to show anymore (ps: but it has to be opened before).
2. You can open form2, and just after that you can call form1.Close() method.

private void button1_Click(object sender, EventArgs e)
        {
//showing the form 2
Form form2 = new Form();
form2.show();
//hiding the form 1:
this.hide();
        }

if you use the show dialog, you cant hide the form1 afaik.

but how to close hidden form that we have hidden ,because on form2 i do not have button to go back

at the top of Form1 write:

using System.Threading;

after that make a button that open Form2 like this:

private void button1_Click(object sender, EventArgs e)
        {
            Form2 frm2 = new Form2();
            frm2.Show(); this.Hide();
            new Thread(new ParameterizedThreadStart(IsOpen)).Start(Prodacts);
        }

and write also this in Form1 after the Button Code:

delegate void FormShow(object onj);
        private void IsOpen(object obj)
        {
            bool isFormOpen = false;
            foreach (Form frm in Application.OpenForms)
                if (frm.Equals((Form)obj))
                    isFormOpen = true;
            if (!isFormOpen)
            {
                if (this.InvokeRequired)
                    this.Invoke(new FormShow(IsOpen), obj);
                else
                    this.Close();
            }
            else
            {
                Thread.Sleep(0);
                new Thread(new ParameterizedThreadStart(IsOpen)).Start((Form)obj);
            }
        }

it is working but there is still problem of closing hidden form ....application remains open in task manager how to close hidden form?

This article has been dead for over six months. Start a new discussion instead.