Getting Started with Windows Forms Designer in .NET Core


Isn't it fun,

to instantly listen to a blog on the go? PLAY !

 
 

Windows-Forms-Designer

The new feature Windows Forms Designer is now available with the .NET Core which is released in Nov 2020. It is used in the .NET Framework but now we can use it in the .NET Core by just enable this tool from the Tools option of the visual studio.

Table of Content

It is available with visual studio’s latest version 2019 and preview version of it.

What is Windows Forms Designer?

Windows Forms Designer in the visual studio provides a quick development solution for creating the Windows Form based application. With this tool, we can easily add the controls, manipulate them, arrange them, and easily code for their event handle.

Using Windows Forms, we can build a rich and interactive user interface, display and manipulate data, and deploy apps to client computers.

Functionality

Using Windows Forms Designer, we can use:

1. Data control, add component, and windows-based controls to a form.

2. Double-click on the form and write the code in the load event for that form.

3. Edit control’s property by selecting the control and edit its property.

4. We can drag and drop the control using the mouse and place it wherever we want.

5. We can place our controls using short keys. Adjust the placement using ctrl + click, and adjust the control’s size using the Shift + click.

Example:


Step 1: How to Create Project

Let’s see how it works. First, open the visual studio 2019 and create the new project Windows Form App (.NET Core).

Open the project and you will see something like this below-attached snap.

If you will get some error according to the project then you can use the .NET Framework based windows forms or just try to reload the project in the solution explorer. Windows Forms will take some time to load.

Now let’s have a look how it looks like when we create the project.

Figure 1.0 Created Project

As we can see in the above figure, there is a form1.cs file which displays the design of the form in which we can add controls.




Step 2: Create Simple Form

First in this form, Drag and drop the controls like ‘Label’, ‘TextBox’, and ‘Button’ to create the simple registration form as below snap.

Figure 2.0 Registration Form

Here on the left side, we can see the tool box from which we will add control, and on the right side is the property of the controls from which we will change its properties.


Step 3: Event Handler (On button click)

Now after double click on the button, we will redirect to the ‘button1_Click’ in the form1.cs file. On button click event show the message using the ‘MessageBox.Show()’ property. We have attached the code below.

usingSystem.ComponentModel; usingSystem.Data; usingSystem.Drawing; usingSystem.Linq; usingSystem.Text; usingSystem.Threading.Tasks; usingSystem.Windows.Forms; namespaceWindowsFormsDesignerApp { publicpartialclassForm1 : Form { publicForm1() { InitializeComponent(); } privatevoid Form1_Load(object sender, EventArgs e) { } privatevoid button1_Click(object sender, EventArgs e) { MessageBox.Show("Successfully Registered"); } } }

Figure 3.0 Output

Project will run the forms according to the program.cs file.

namespaceWindowsFormsDesignerApp { staticclassProgram { /// /// The main entry point for the application. /// [STAThread] staticvoidMain() { Application.SetHighDpiMode(HighDpiMode.SystemAware); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1()); } } }

We have applied here the STAThread attribute to specify that our windows forms application is a single-threaded apartment. To apply operating system styles to our forms add ‘EnableVisualStyles()’.


Searching for Dedicated ASP.Net Core Web Developer ?

Your Search ends here.


We can view the form and customize it. Like give the background color, image, and opacity, and many more properties are there. Something like this:

Figure 4.0 Customize Windows Form

In this preview version of the windows forms, designers in the .NET Core is limited. This means it supports minimum numbers of the controls and properties. It will be more functional and supports more features in the next version.

Supported controls in preview 1 is:

  1. Pointer
  2. Button
  3. Label
  4. CheckBox
  5. CheckedListBox
  6. ComboBox
  7. DateTimePicker
  8. LinkLabel
  9. ListBox
  10. ListView
  11. MaskedTextBox
  12. MonthCalendar
  13. NumericUpDown
  14. PictureBox
  15. ProgressBar
  16. RadioButton
  17. RichTextBox
  18. TextBox
  19. TreeView


Advantages of Windows Forms Designer

With the windows form designer, we can develop smart clients which means it is easy to deploy and update, we can work on it with the internet and without the internet, and can access the local resources in a more secure manner.

We can build a more attractive UI using a windows forms designer because of the drag and drop controls. And we can place it wherever we want to make UI better in the form. So, we can build rich, and interactive UI.

Other applications display the data from the database, XML file, and other data sources. But in windows forms, there is one flexible control called DataGridView. In which each and every data displayed in tabular forms. To bind data from the database, windows forms introduce the BindingSource which represents the connection to the data source, editing data source, and save changes, etc.

After all of this, we must send this application to the user. So, the user can run it on its own computer. In windows forms there is ClickOnce technology manages all the elements and dependencies in our application and makes sure that the application is correctly installed.

There are many other features in windows forms designer that make implementing common tasks easy. Such as creating a dialog box, and supports localization. Using localization, we can use this form to display in a different language.

Conclusion

Visual studio provides the windows forms to the .NET framework earlier, but now visual studio also provides the windows forms to the .NET core released recently. As we have seen in this blog, how windows forms are helpful in .NET core. Windows forms provide the fast and easy development of any application. Because it offers the drag and drops functionality and event handling with just a double click.We can also build windows form using the command line interface. Hope you acquired a detail understanding of windows forms designer in .NET Core.

Windows-Forms-Designer

The new feature Windows Forms Designer is now available with the .NET Core which is released in Nov 2020. It is used in the .NET Framework but now we can use it in the .NET Core by just enable this tool from the Tools option of the visual studio.

Table of Content

It is available with visual studio’s latest version 2019 and preview version of it.

What is Windows Forms Designer?

Windows Forms Designer in the visual studio provides a quick development solution for creating the Windows Form based application. With this tool, we can easily add the controls, manipulate them, arrange them, and easily code for their event handle.

Using Windows Forms, we can build a rich and interactive user interface, display and manipulate data, and deploy apps to client computers.

Functionality

Using Windows Forms Designer, we can use:

1. Data control, add component, and windows-based controls to a form.

2. Double-click on the form and write the code in the load event for that form.

3. Edit control’s property by selecting the control and edit its property.

4. We can drag and drop the control using the mouse and place it wherever we want.

5. We can place our controls using short keys. Adjust the placement using ctrl + click, and adjust the control’s size using the Shift + click.

Example:


Step 1: How to Create Project

Let’s see how it works. First, open the visual studio 2019 and create the new project Windows Form App (.NET Core).

Open the project and you will see something like this below-attached snap.

If you will get some error according to the project then you can use the .NET Framework based windows forms or just try to reload the project in the solution explorer. Windows Forms will take some time to load.

Now let’s have a look how it looks like when we create the project.

Figure 1.0 Created Project

As we can see in the above figure, there is a form1.cs file which displays the design of the form in which we can add controls.




Step 2: Create Simple Form

First in this form, Drag and drop the controls like ‘Label’, ‘TextBox’, and ‘Button’ to create the simple registration form as below snap.

Figure 2.0 Registration Form

Here on the left side, we can see the tool box from which we will add control, and on the right side is the property of the controls from which we will change its properties.


Step 3: Event Handler (On button click)

Now after double click on the button, we will redirect to the ‘button1_Click’ in the form1.cs file. On button click event show the message using the ‘MessageBox.Show()’ property. We have attached the code below.

usingSystem.ComponentModel; usingSystem.Data; usingSystem.Drawing; usingSystem.Linq; usingSystem.Text; usingSystem.Threading.Tasks; usingSystem.Windows.Forms; namespaceWindowsFormsDesignerApp { publicpartialclassForm1 : Form { publicForm1() { InitializeComponent(); } privatevoid Form1_Load(object sender, EventArgs e) { } privatevoid button1_Click(object sender, EventArgs e) { MessageBox.Show("Successfully Registered"); } } }

Figure 3.0 Output

Project will run the forms according to the program.cs file.

namespaceWindowsFormsDesignerApp { staticclassProgram { /// /// The main entry point for the application. /// [STAThread] staticvoidMain() { Application.SetHighDpiMode(HighDpiMode.SystemAware); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1()); } } }

We have applied here the STAThread attribute to specify that our windows forms application is a single-threaded apartment. To apply operating system styles to our forms add ‘EnableVisualStyles()’.


Searching for Dedicated ASP.Net Core Web Developer ?

Your Search ends here.


We can view the form and customize it. Like give the background color, image, and opacity, and many more properties are there. Something like this:

Figure 4.0 Customize Windows Form

In this preview version of the windows forms, designers in the .NET Core is limited. This means it supports minimum numbers of the controls and properties. It will be more functional and supports more features in the next version.

Supported controls in preview 1 is:

  1. Pointer
  2. Button
  3. Label
  4. CheckBox
  5. CheckedListBox
  6. ComboBox
  7. DateTimePicker
  8. LinkLabel
  9. ListBox
  10. ListView
  11. MaskedTextBox
  12. MonthCalendar
  13. NumericUpDown
  14. PictureBox
  15. ProgressBar
  16. RadioButton
  17. RichTextBox
  18. TextBox
  19. TreeView


Advantages of Windows Forms Designer

With the windows form designer, we can develop smart clients which means it is easy to deploy and update, we can work on it with the internet and without the internet, and can access the local resources in a more secure manner.

We can build a more attractive UI using a windows forms designer because of the drag and drop controls. And we can place it wherever we want to make UI better in the form. So, we can build rich, and interactive UI.

Other applications display the data from the database, XML file, and other data sources. But in windows forms, there is one flexible control called DataGridView. In which each and every data displayed in tabular forms. To bind data from the database, windows forms introduce the BindingSource which represents the connection to the data source, editing data source, and save changes, etc.

After all of this, we must send this application to the user. So, the user can run it on its own computer. In windows forms there is ClickOnce technology manages all the elements and dependencies in our application and makes sure that the application is correctly installed.

There are many other features in windows forms designer that make implementing common tasks easy. Such as creating a dialog box, and supports localization. Using localization, we can use this form to display in a different language.

Conclusion

Visual studio provides the windows forms to the .NET framework earlier, but now visual studio also provides the windows forms to the .NET core released recently. As we have seen in this blog, how windows forms are helpful in .NET core. Windows forms provide the fast and easy development of any application. Because it offers the drag and drops functionality and event handling with just a double click.We can also build windows form using the command line interface. Hope you acquired a detail understanding of windows forms designer in .NET Core.