1.1建立Windows應用程序windows
打開visual studio2017 在菜單欄選擇「文件」→「新建」→「項目」spa
出現以下圖後,點開visual C#選擇Windows桌面,找到Windows窗體應用(NET.Framework)code
輸入項目名,保存地址後確認。orm
打開後;blog
public Form1() { InitializeComponent(); } //進行操做下一步的代碼 private void button1_Click(object sender, EventArgs e) { //消息框:
//MessageBox.Show("點","點他");//內容,標題 //MessageBox.Show("點", "點他",MessageBoxButtons.RetryCancel);//從新 MessageBox.Show("點","點他",MessageBoxButtons.YesNoCancel,MessageBoxIcon.Asterisk); //從新,提示圖標 DialogResult result;//消息框返回值 result = MessageBox.Show("點", "點他", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Asterisk); if (result==DialogResult.Yes) { MessageBox.Show("你選了'是'"); } else { MessageBox.Show("你沒選'是'"); } } private void Form1_Load(object sender, EventArgs e) { Text = "花裏胡哨";//能夠改變窗體的標題 MessageBox.Show("box 展現"); } private void Form1_Click(object sender, EventArgs e) {
//換背景顏色 if (BackColor == Color.Red) { BackColor = Color.Yellow; } else if (BackColor == Color.Yellow) { BackColor = Color.Green; } else { BackColor = Color.Red; } Application.Exit();//結束程序的進程 } private void Form1_FormClosing(object sender, FormClosingEventArgs e) { DialogResult result = MessageBox.Show("肯定關閉嗎","提示",MessageBoxButtons.YesNoCancel,MessageBoxIcon.Information); if (result == DialogResult.Yes)//選擇的結果(枚舉) { MessageBox.Show("真的關了哈", "提示"); } else { e.Cancel = true;//選擇爲取消 } }