Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

.net

winforms

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.

like image 523
user850010 Avatar asked Aug 17 '11 20:08

user850010


2 Answers

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();
like image 148
Brian Driscoll Avatar answered Oct 05 '22 00:10

Brian Driscoll


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;
            }
        }
like image 43
Levitikon Avatar answered Oct 05 '22 01:10

Levitikon