C#用记事本编写简单WinForm窗体程序
作者:cvMat 时间:2021-12-19 13:02:31
平时我们编写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用于指定源文件的文件路径
来源:https://blog.csdn.net/cvMat/article/details/53516689
标签:C#,记事本,WinForm,窗体
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Java实现二分查找算法实例分析
2022-06-01 07:30:32
Scala方法与函数使用和定义详解
2021-10-05 06:34:12
如何解决Spring in action @valid验证不生效的问题
2023-08-29 07:59:56
Java语言实现简单FTP软件 FTP软件效果图预览之上传功能(3)
2022-03-28 10:16:21
![](https://img.aspxhome.com/file/2023/3/72383_0s.png)
浅谈springboot一个service内组件的加载顺序
2023-12-10 12:47:12
redis redisson 集合的使用案例(RList、Rset、RMap)
2023-11-13 13:50:21
java实现简单的猜数字小游戏
2023-11-11 12:55:40
![](https://img.aspxhome.com/file/2023/5/59055_0s.jpg)
三种Java自定义DNS解析器方法与实践
2022-01-13 10:12:11
Mybatis配置之typeAlias标签的用法
2023-11-27 20:18:20
![](https://img.aspxhome.com/file/2023/6/60446_0s.jpg)
SpringCloud @FeignClient参数的用法解析
2022-11-25 06:31:37
Java实现时间日期格式转换示例
2023-06-06 04:45:11
SpringBoot注册Filter的两种实现方式
2023-01-01 10:26:05
![](https://img.aspxhome.com/file/2023/0/79230_0s.jpg)
C#多态详解
2023-06-25 13:42:20
![](https://img.aspxhome.com/file/2023/1/78191_0s.png)
Unity实现颜色渐变滑动条
2023-11-28 10:54:51
![](https://img.aspxhome.com/file/2023/8/83348_0s.gif)
Java项目导入IDEA的流程配置以及常见问题解决方法
2021-11-21 10:02:24
![](https://img.aspxhome.com/file/2023/1/76521_0s.jpg)
Java使用组合模式实现表示公司组织结构功能示例
2022-07-31 08:03:37
![](https://img.aspxhome.com/file/2023/4/75404_0s.png)
基于Spring Boot保护Web应用程序
2022-11-15 19:14:48
详解基于spring多数据源动态调用及其事务处理
2023-06-23 14:37:25
![](https://img.aspxhome.com/file/2023/0/57530_0s.png)
Android RecyclerView使用ListAdapter高效刷新数据的操作方法
2023-06-24 22:22:09
![](https://img.aspxhome.com/file/2023/0/83550_0s.gif)
Java实现淘宝秒杀聚划算抢购自动提醒源码
2022-09-11 10:11:53