欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

C#用记事本编写简单WinForm窗体程序

程序员文章站 2023-11-14 23:40:10
平时我们编写winform程序经常使用vs进行拖控件的方式,这样做虽然简单,但是无法深入了解winform程序的本质。其实,用记事本也可以编写出vs编写的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());
  }
 }
}

2、在windows搜索框输入 cmd,打开控制台,输入以下代码切换目录

cd c:\windows\microsoft.net\framework\v4.0.30319

3、目录切换完毕后,输入以下代码运行

csc.exe /out:e:\hello.exe e:\hello.cs

/out:e:\hello.exe用于指定可执行文件存放的目录和名称
e:\hello.cs用于指定源文件的文件路径

C#用记事本编写简单WinForm窗体程序

C#用记事本编写简单WinForm窗体程序

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。