C# host computer series (1) - project establishment

This article is to explain the first content under the Winform framework of the C#.net platform. It introduces the creation method of the project and some commonly used functions when writing software. I wrote an abstract article about oscilloscopes before. This article explains every step from scratch.

VS2022 and the Winform framework of the C#.net platform are downloaded from Baidu.

1. Create a new project

Double-click to open vs (I use the 2022 version)

Choose to create a new project (select the form application under .net) next step

 Select the save path and name it, the next step

 Select the application framework, the next step

 The creation is complete, generate the working interface, and view the generated files

 

 

 Automatically generated file directory

 

 2. Project file introduction

The main introduction is as follows, and the others are ignored for the time being, and will be explained later

 Click Run, you can see the generated blank window as follows, close the window or click Stop to end the run

 

 Form1.cs (the file where we wrote the code above), right click in the blank space of the window and select View Code to open

 

 ​​​​​​​

 

 Another design code file Form1.Designer.cs (automatically generated) is as follows, click the plus sign + on the left to expand, which is the form design code

What does this automatic generation mean, let's do an experiment

First look at the following line of parameters (for the size of the form)

 Then we drag the form to make the form larger

 

 Looking at the form design code again, you can see that the parameter changes automatically. Conversely, if you change this parameter manually, the corresponding form size will also change accordingly. Throughout the subsequent development, we combined these two characteristics to carry out various designs.

  3. Introduction to control library

During the development process, some common control libraries that need to be used are as follows; back to the main window, click on the toolbox on the left as follows

 Select a control Button (key) and drag it to the window

 You can see the corresponding automatically generated code in the design file

 Here is a brief introduction to how to use these controls

For the button (button) control, we double-click it

 Then such a piece of code is generated. The function of this code is to handle the event after the button is pressed. You can see that the event function is in the Form.cs file

 

 By the way, here is an introduction to the operation of deleting this code. Directly deleting the code of the event will trigger an error

 

The way to deal with it is to double-click the error report below, and delete the error code in the design file, and it will be operated frequently in the future

Guess you like

Origin blog.csdn.net/qq_49552487/article/details/127971627