From the course: Introducing Desktop and .NET Core

Create your first WinForms app on .NET Core - .NET Tutorial

From the course: Introducing Desktop and .NET Core

Create your first WinForms app on .NET Core

- Hi, my name is Olia Gavrysh. I'm program manager on .NET team at Microsoft. And in this video, you will learn how to create your first WinForms application on .NET Core. Windows Forms, or WinForms for short, is a desktop application, meaning it runs on your machine as opposed to, let's say, in a browser. It is one of the easiest way to get started with programming because it does not require any setup and, with the graphical designer, you can create user interface, visual part that allows users to interact with your program, in no time. Let's see. All right, I'm going to start Visual Studio. I'm using Visual Studio 2019, and I will choose create a new project. In the search box, I will type WinForms. And as you can see, there are a few options. There is Windows Forms App for .NET Core and Windows Forms App for .NET Framework. We have another video where I explain the difference and how to choose one for your application. In my case, I will go with .NET Core. There are also different options for programming language. There is a C# and Visual Basic. I will choose C#. So WinForms app .NET Core with C#, and I will click next. In this dialogue, you specify project name, location, and solution name. And if something looks confusing, there are information icons that can give you a tip. Like this one, "Solution is a container for your projects." I'm going to click create, and Visual Studio will create an empty WinForms application for me. This application is already ready to be run. So first thing, let's run it and see how it works. To do that, I'm going to click on the green triangle that has the name of my application. In my case, it's WinFormsApp17. And you can see an empty form. This is windows form and that's how the technology got its name. And of course, now it is empty because we just created it. It only has buttons minimize, maximize, and close. And when you click close it will automatically stop application execution. Now let's look at the files that ID created for us to just so I'm going to look at Solution Explorer. If Solution Explorer is not shown by default in visual studio it can easily find it in the search box by typing Solution Explorer. Here you can see your solution, your project your solution can have one or more projects and files in each project. My project has dependencies Form1.cs and program.cs. Dependencies is a place that has information on all the core that I'm using from other sources. It can be other projects or.NET Framework or it can be third-party components Form1.cs and program.cs are C Sharp files. CS stands for C Sharp. And if I double click Form1 it will open WinForms designer. Here I can see the form that we saw before when we run our application and with the help of graphical designer. It's very easy to add controls to the form. If you look at toolbox and again, if it's not open you can search for toolbox in the search and in the toolbox you can see various controls that can be added to the form. Let's add a button by double clicking on it. Then you can move the button along the form change its dimension and other properties. I'm going to add another control that is called tags box. So here you can see that I can position different controls on my form. Every controls has its properties and to change those properties, we go to property browser. Again, if it's not open by default in your visual studio just search for property browser in the search box. Here you can see that each control has properties like name it's very first one. And you can assign your name. For example, let's call it. HelloTextbox, it also has font. Let's make it bigger Color, let's make it blue and others. We can also change properties for the button the same way. So let's call it HelloButton And let's change the text on that bottom. Now, if we run our application, we can see that our form now have the controls we just added but if we click on the button, nothing happens. Now let's add some functionality to our code. If I double click on the button it will automatically take me to the place in my code where I can add the event that will happen once we click on the button. So here I can call the text box And intelliSense automatically suggest me. HelloTextbox put dot and say text and assign that property to whatever I want. At the end of each line we put semi column. All right, now let's run it again and see what happens now. Now when we click, we get the text. That was your first WinForms application on .NET core Thank you very much for watching and happy coding.

Contents