开发者

Adding new form in the same window

开发者 https://www.devze.com 2023-03-24 18:23 出处:网络
I have this link开发者_StackOverflow社区 on my windows form in C# on visual studio: private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)

I have this link开发者_StackOverflow社区 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?


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();


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.


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


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


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#?

0

精彩评论

暂无评论...
验证码 换一张
取 消