平時(shí)我們編寫WinForm程序經(jīng)常使用VS進(jìn)行拖控件的方式,這樣做雖然簡單,但是無法深入了解WinForm程序的本質(zhì)。其實(shí),用記事本也可以編寫出VS編寫的WinForm程序。還是直接看代碼吧:
創(chuàng)新互聯(lián)專注于開封企業(yè)網(wǎng)站建設(shè),成都響應(yīng)式網(wǎng)站建設(shè)公司,成都做商城網(wǎng)站。開封網(wǎng)站建設(shè)公司,為開封等地區(qū)提供建站服務(wù)。全流程按需網(wǎng)站制作,專業(yè)設(shè)計(jì),全程項(xiàng)目跟蹤,創(chuàng)新互聯(lián)專業(yè)和態(tài)度為您提供的服務(wù)
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(); //設(shè)置按鈕屬性 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; //設(shè)置按鈕控件點(diǎn)擊事件 this.btnClose.Click += new System.EventHandler(this.btnClose_Click); //將構(gòu)造的控件添加到窗體Controls控件集合 this.Controls.Add(btnClose); } //按鈕點(diǎn)擊事件 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、目錄切換完畢后,輸入以下代碼運(yùn)行
csc.exe /out:e:\hello.exe e:\hello.cs
/out:e:\hello.exe用于指定可執(zhí)行文件存放的目錄和名稱
e:\hello.cs用于指定源文件的文件路徑
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持創(chuàng)新互聯(lián)。
網(wǎng)站名稱:C#用記事本編寫簡單WinForm窗體程序
標(biāo)題路徑:http://jinyejixie.com/article18/ijgggp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供企業(yè)建站、網(wǎng)站導(dǎo)航、域名注冊、網(wǎng)站策劃、虛擬主機(jī)、ChatGPT
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)