Hi , I am new in C# programming and I am trying to implementate something like site in c#.

On the top of my form1 I have four LinkLabels and when an user clicks one , he goes to another form but the initial form1 still exists.

I am trying this code :

private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
     form2 form= new form2();
     form1 new_form = new form1();
     form.show();
     new_form.Close(); //or new_form.Hide(); is the same ??
}

What is my fault ???

Thank you

Often closing the main form will terminate the app, you can just hide it.

Normally programs that appear to change from one screen to another and remove others such as login boxes to a main form etc, tend not to work the way people might imagine.

What you could do is rather than use the button click event in the form to create a new form, use an event in your main program.cs which sends a close event to the first form, and opens a new form.

Often closing the main form will terminate the app, you can just hide it.

Normally programs that appear to change from one screen to another and remove others such as login boxes to a main form etc, tend not to work the way people might imagine.

What you could do is rather than use the button click event in the form to create a new form, use an event in your main program.cs which sends a close event to the first form, and opens a new form.

I tried
this.Hide();

The form disappeared but I could not exit from form2.

Your solution I did't understand. Could you help me with code ??

Thanks again

Ok, your example of your problem has many questions

You reference 2 different forms in that procedure. You seem to have 2 forms, form1, form2.

In that procedure you create a new copy of both of them
You show one, and hide/close the other.

Surely you wanted to hide/close the current form? Or, are you trying to toggle between 2 form?

Yeah , I want to toggle between the two forms.

MayBE if I create a new form, for example login form, then I could hide the form 1 and form 2.
But I will have the same problem in login page.

No
if you have the 2 forms as private variables, create them on your main forms creation but only show them as you need them, you dont ever need to make new instances of them again.

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