How to open a new window in Windows Forms in .NET?

2020-08-12 18:08发布

问题:

I have an application that among other things has an Edit Button and when the user clicks on that button I want a new window to open with various textboxes for editing purposes.

I can create a new window with code like

Form editform = new Form();

But I want to design that window in the Designer too.

回答1:

In Visual Studio, right-click on your project and select Add->Windows Form. That will give you a new form to work with. Lay it out how you want. Then you can launch the window from your main window with code similar to the following:

MyEditForm form = new MyEditForm();
form.Show();


回答2:

To answer Rick's comment on Brian's answer:

        using (var login = new Login())
        {
            switch(login.ShowDialog())
            {
                case DialogResult.OK:
                    Application.Run(new Studio());
                break;
            }
        }


标签: c# .net winforms