当前位置:网站首页>C application interface development foundation - form control (1) - form form
C application interface development foundation - form control (1) - form form
2022-07-03 01:33:00 【DXB2021】
From forms
establish WinForm Program
establish WinForm Procedure steps
open Visual Studio, Click on “ Create a new project ”, Using shortcut keys Ctrl+Shift+N It can be opened quickly “ New projects ” Dialog box .

Select... From the pull down menu “C#”、“Windows”、“ desktop ” in , Select in the list box “Windows Form application (.NET Framework)”.

Click on “ next step ”.
Click on “ establish ”.

In Solution Explorer , double-click Program.cs file , Will jump to Windows Console application interface , stay “ edit ” In the window is an automatically generated WinForm Program .

The code is as follows :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApp1
{
internal static class Program
{
/// <summary>
/// The main entry point for the application .
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}Click again “ start-up ” Key , A blank form will pop up .

The essence of creating a form
The essence of a form is to use System.Windows.Forms.Form Class or a derived class of this class .
Right click “ forms ” after , choice “ Look at the code ” command , It will jump to Form1.cs file .


The code is as follows :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
}
}
Add and delete forms
Right-click the project name WindowsFormsApp1, Choose... From the shortcut menu that pops up “ add to ”-“Windows forms ” perhaps “ add to ”-“ New item ” command .

Last in “ Add a new item ” Select... From the Christmas box “ forms (Windows forms )”.

Delete form , Just in the solution manager , Select the name of the form to delete , Right click , Select from the pop-up shortcut menu “ Delete ” Command is enough .

Properties of the form
1、“ attribute ” panel
open “ attribute ” The panel has the following three methods :
(1)
Right click command

(2)
“ View ” command

(3)
The lower right corner

2、C# WinForm Form basic properties
(1) Attribute values in window styles , Can be used to change the icon 、 Maximize window transparency .
| Property value | explain |
| Icon | Change icon style ( Top left Icon ) |
| MaximizeBox:true; | Display the maximize button in the upper right corner |
| MinimizeBox:true; | Display the minimize button in the upper right corner |
| ShowInco:true; | Display the small icon in the upper left corner |
| ShowInTaskbar:ture; | The form is displayed in the taskbar |
| TopMost:ture; | The window is displayed at the top |
| Opacity:100% | Whole window transparency |
(2) Attribute values in the layout , It can be used to change the size of the form and the display position of the form after starting the program .
| Property value | explain |
| AutoScroll:true/false; | If the control exceeds the window, whether to automatically display the scroll bar |
| AutoSize:true/false; | Whether the scope of the window will exceed the size of the control |
| MaximumSize:0,0; | The maximum size a window can be dragged |
| MinimumSize:0,0; | The smallest size a window can drag |
| Size:300,300; | The default size when the window is opened |
| StartPosition:centerScreen; | The default desktop location when the window is opened , In the middle |
| WindowState:Maximized; | The default open window is maximized . |
(3) Attribute value of appearance , It is mainly used to change the form color 、 Font, title, etc .
| Property value | explain |
| Font: Song style ,9pt; | You can change the font size , The larger the font, the larger the control |
| Text; | Input text |
| TextAlign; | Text location |
| FormBorderStyle:FixedSingle; | The window cannot be dragged |
| FormBorderStyle:None; | Hide the border of the window |
| DropDownStyle:DropDownList; | Make the drop-down box unable to enter text |
3、 Set form properties
The icon of the form is system Default icon .

Change icon , stay “ attribute ” The palette , choice Icon character

Color of the form And background , adopt BackgroundImage Property to set . choice “ attribute ” In the panel BackgroundImage attribute .

Common events for forms
The so-called event , It means what's going to happen , It can be simply understood as the user's operation , It is triggered by an object . All events of the form , Can be in “ attribute ” Panel to view .
1、 Add event
Add an event to the form , Just select the event to be added in the event panel ,Load Double click in the following space , The corresponding event will be generated automatically .
(1) When the form is loaded , A form loading event will be triggered Load.


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
MessageBox.Show(" Form loading completed ");
}
}
}
(2) When you click the form , Trigger Click( single click ) event .

Click double-click .

The code is as follows :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
MessageBox.Show(" Form loading completed ");
}
private void Form1_Click(object sender, EventArgs e)
{
MessageBox.Show(" Click form ");
}
}
}

(3) When you close the form , Trigger FormClosing( close ) event

The code is as follows :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
MessageBox.Show(" Form loading completed ");
}
private void Form1_Click(object sender, EventArgs e)
{
MessageBox.Show(" Click form ");
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
MessageBox.Show(" Are you sure you want to close the form ?");
}
}
}

2、 Delete event
Do not understand , Don't master .
Display and hide of forms
Form identifier .Show()
Form identifier .Hide()
边栏推荐
- uniapp组件-uni-notice-bar通告栏
- Machine learning terminology
- wirehark数据分析与取证A.pacapng
- Androd gradle's substitution of its use module dependency
- Give you an array numbers that may have duplicate element values. It was originally an array arranged in ascending order, and it was rotated once according to the above situation. Please return the sm
- Kivy tutorial how to create drop-down lists in Kivy
- The thread reuse problem of PageHelper using ThreadLocal, did you use it correctly?
- MySQL - database query - condition query
- SSL flood attack of DDoS attack
- Steps to obtain SSL certificate private key private key file
猜你喜欢

Basic remote connection tool xshell
![[fh-gfsk] fh-gfsk signal analysis and blind demodulation research](/img/8a/8ca80f51a03341c982d52980c54b01.png)
[fh-gfsk] fh-gfsk signal analysis and blind demodulation research

wirehark数据分析与取证A.pacapng

传输层 TCP主要特点和TCP连接

leetcode 6103 — 从树中删除边的最小分数

How is the mask effect achieved in the LPL ban/pick selection stage?

MySQL basics 03 introduction to MySQL types

CF1617B Madoka and the Elegant Gift、CF1654C Alice and the Cake、 CF1696C Fishingprince Plays With Arr

MySQL --- 数据库查询 - 基本查询

Niu Ke swipes questions and clocks in
随机推荐
MySQL basic usage 02
[interview question] 1369 when can't I use arrow function?
Key wizard play strange learning - front desk and Intranet send background verification code
[Androd] Gradle 使用技巧之模块依赖替换
串口抓包/截断工具的安装及使用详解
Mathematical knowledge: Nim game game theory
【我的OpenGL学习进阶之旅】关于欧拉角、旋转顺序、旋转矩阵、四元数等知识的整理
Kivy教程大全之如何在 Kivy 中创建下拉列表
产业互联网的产业范畴足够大 消费互联网时代仅是一个局限在互联网行业的存在
Common English Vocabulary
Do not log in or log in to solve the problem that the Oracle database account is locked.
Detailed explanation of Q-learning examples of reinforcement learning
[Arduino experiment 17 L298N motor drive module]
Now that the teenager has returned, the world's fireworks are the most soothing and ordinary people return to work~
C#应用程序界面开发基础——窗体控制(2)——MDI窗体
2022 cable crane driver examination registration and cable crane driver certificate examination
C application interface development foundation - form control (2) - MDI form
The difference between tail -f, tail -f and tail
Database SQL language 02 connection query
Top ten regular spot trading platforms 2022