C#用记事本编写简单WinForm窗体程序-创新互联
平时我们编写WinForm程序经常使用VS进行拖控件的方式,这样做虽然简单,但是无法深入了解WinForm程序的本质。其实,用记事本也可以编写出VS编写的WinForm程序。还是直接看代码吧:

1、打开记事本,写入以下代码,另存为hello.cs文件
using System;
using System.Windows.Forms;
namespace Hello
{
public class Form1:Form
{
private System.Windows.Forms.Button btnClose;
public Form1()
{
this.Text = "Form1窗体";
btnClose = new System.Windows.Forms.Button();
//将窗体挂起
this.SuspendLayout();
//设置按钮属性
this.btnClose.Location = new System.Drawing.Point(20,20);
this.btnClose.Size = new System.Drawing.Size(100,25);
this.btnClose.Name = "btnClose";
this.btnClose.Text = "按钮";
this.btnClose.UseVisualStyleBackColor = true;
//设置按钮控件点击事件
this.btnClose.Click += new System.EventHandler(this.btnClose_Click);
//将构造的控件添加到窗体Controls控件集合
this.Controls.Add(btnClose);
}
//按钮点击事件
private void btnClose_Click(object sender,EventArgs e)
{
this.Close();
}
}
public class Program
{
//程序入口
public static void Main()
{
Application.Run(new Form1());
}
}
}
另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。
网页题目:C#用记事本编写简单WinForm窗体程序-创新互联
本文来源:http://www.jxjierui.cn/article/cdopgg.html


咨询
建站咨询
