WinForm 是 Windows Form 的简称,是基于 .NET Framework 平台的客户端(PC软件)开发技术,是 C# 语言中的一个重要应用。
.NET 提供了大量 Windows 风格的控件和事件,可以直接拿来使用。
窗体是由当前类继承 .Net提供Form类所形成的窗体
设置当前窗体的一些常用属性(在构造函数里)
this.Name = "占山";
this.Text = "123";
this.ClientSize = new Size(540, 500);
Button 按钮
private Button Btn; 先定义一个Button变量
this.Btn = new Button();
this.Controls.Add(this.Btn);//将创建好的按钮添加到窗体内,这样才可以显示
this.Btn.Text = "按钮1";
this.Btn.Location = new Point(100, 150);//左上角起始位置
Label 标签
this.label = new Label();
this.Controls.Add(this.label);
this.label.Text = "姓名";
this.label.Font = new Font("楷书", 25);
控件想要显示在窗体还需要添加,如 this.Controls.Add( Btn );
internal class MyFrom: Form
{
private Button Btn;
private Label lable1;
public MyFrom()
{
this.Name = "占山";
this.Text = "123";
this.ClientSize = new Size(540, 500);
this.Btn = new Button();
this.Controls.Add(this.Btn);
this.Btn.Text = "按钮1";
this.Btn.Location = new Point(100, 150);
this.lable1 = new Label();
this.Controls.Add(this.lable1);
this.lable1.Text = "姓名";
this.lable1.Font = new Font("楷书", 25);
}
}