安裝完Microsoft Visual Studio後
可以開始譔寫第一隻程式
首先開啟Visual Studio
從左上角File -> New -> Project 新建立專案
選擇Visual C#裡的Windows Forms Application
且在下方Name輸入專案名稱,Location選擇儲存路徑按下OK
開啟專案後會進入一個Windows Forms介面
從左方工具列拉選所需元件近入Forms (Lable,TextBox,Button)
Lable為顥示字串(輸出)
TextBox為輸入字串(輸入)
Button為一按鈕(動作)
點選Lable1後 可由右下
角修改特性(字體,大小,位置,顏色,文字...等)
由Text可修改顥示字串
點選Textbox1後 一樣可修改特性
將Textbox1的Name改為Name_Text(更改元件名稱好讓自己以後寫程式名稱太多不會亂掉)
點選Lable2 更改特性Visble (true -> false) (執行程式時不顯示元件)
連點2下Button進入程式碼譔寫
private void button1_Click(object sender, EventArgs e) //按下Button後執行事件
{
label2.Visible = true; // 顥示Label2
label2.Text = "Hello! " + Name_Text.Text.ToString(); // Label2的Text改為Hello! +在Name_Text所輸入的字串
}
點選上方Start
在Name_Text輸入姓名
按下Button
是否很簡單!
留言列表