服务器之家:专注于VPS、云服务器配置技术及软件下载分享
分类导航

PHP教程|ASP.NET教程|Java教程|ASP教程|编程技术|正则表达式|C/C++|IOS|C#|Swift|Android|VB|R语言|JavaScript|易语言|vb.net|

服务器之家 - 编程语言 - C# - C#用记事本编写简单WinForm窗体程序

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

2022-07-14 08:36cvMat C#

这篇文章主要为大家详细介绍了C#用记事本编写简单WinForm窗体程序,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

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

1、打开记事本,写入以下代码,另存为hello.cs文件

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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,打开控制台,输入以下代码切换目录

?
1
cd C:\Windows\Microsoft.NET\Framework\v4.0.30319

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

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

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

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

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

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

原文链接:https://blog.csdn.net/cvMat/article/details/53516689

延伸 · 阅读

精彩推荐