Show form from another form

When I want to display a form (C #) by clicking a button in another form, I usually create an object from the form I want to show and use the show method:

        Form2 f2 = new Form2();
        f2.Show();

or I work with the "Owner":

        Form2 tempForm = new Form2();
        this.AddOwnedForm(tempForm);
        tempForm.Show();

the two methods generate the same results, but what is the best and what are the differences between them?

+3
source share
2 answers

The only difference besides the name is that in the second you call AddOwnedForm , and in the first you do not. After looking at the documentation, we see:

, . , Form2 Form1, Form1 , Form2 . . , , .

, , , , AddOwnedForm. , .

+7

Microsoft Form f = new Form(); f.Show(); Windows Forms , , , ( ) . Show(), f.Visible = true; .

AddOwnedForm(), , . , .

+3

Source: https://habr.com/ru/post/1740697/


All Articles