Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

change active form to show another form

I have a Form1 and another one that I added. Form1 is being run by program.cs at the start. I need to hide Form1 and show options form by the press of a button.

    private void submitPassword_Click(object sender, EventArgs e)
    {
        options optionForm = new options();
        optionForm.Show();
    }

the above code opens the options form on top, but I need it to replace the current form. how can I achieve this?

like image 737
Ahoura Ghotbi Avatar asked Oct 24 '25 20:10

Ahoura Ghotbi


2 Answers

Hide current form using this.Close() before showing new one and make sure you are using parameterless Application.Run so program won't close when you close it's main form.

You can use "Hide" and "Show" method :

private void submitPassword_Click(object sender, EventArgs e)

{

    options optionForm = new options();

    this.Hide();

    optionForm.Show();
}
like image 26
saeid1389 Avatar answered Oct 27 '25 10:10

saeid1389