akageek
akageek

Reputation: 87

Adding new form in the same window

I have this link on my windows form in C# on visual studio:

private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            // Show another form.
            Form2 f2 = new Form2();
            f2.Show(this);
            linkLabel1.LinkVisited = true;
        }

I want when i press the link,the new form which will be created to be on the same window and not appeared on another window.How can i do this?

Upvotes: 1

Views: 16481

Answers (5)

Hnin Htet Htet Aung
Hnin Htet Htet Aung

Reputation: 521

Form.ShowDialog() didn't work for me. So I tried "MDI Container". Please check the link below.

How to open a new form window within same window in C#?

Upvotes: 0

vidhi
vidhi

Reputation: 431

you can create UserControls and swap the visible UserControl on a Form. To create user control check this link : create usercontrol

Upvotes: 0

Bas
Bas

Reputation: 27095

A form is inherently a Window. If you want to do it without creating multiple Windows, create UserControls and swap the visible UserControl on a Form.

Upvotes: 3

Jamie Dixon
Jamie Dixon

Reputation: 54001

The way I've usually seen this done is the show the new form and hide the previous one.

This gives the appearance of the same window being used.

Something like:

this.Hide();
f2.Show();

Upvotes: 3

user195488
user195488

Reputation:

change your .Show to .ShowDialog. This will make it a modal dialog "window".

Upvotes: 0

Related Questions