平时我们编写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用于指定源文件的文件路径
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持移动技术网。
如对本文有疑问, 点击进行留言回复!!
使用Visual Studio2019创建C#项目(窗体应用程序、控制台应用程序、Web应用程序)
C#实现获取本地内网(局域网)和外网(公网)IP地址的方法分析
浅谈Visual Studio 2019 Vue项目的目录结构
网友评论