[問題] 文字方塊控制

看板C_Sharp作者 (!@#$)時間16年前 (2009/11/05 21:40), 編輯推噓2(203)
留言5則, 3人參與, 最新討論串1/1
namespace box { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { this.Text = "sell drinks"; this.BackColor = Color.Yellow; label1.Text = "name"; label2.Text = "how much"; label3.Text = "how many"; label4.Text = "total money"; button1.Text = "蝣箏꺚"; button2.Text = "皜雎妚"; textBox1.BackColor = Color.Yellow; textBox1.Text = "cola"; textBox1.ReadOnly = true; textBox2.BackColor = Color.Yellow; textBox2.Text = "25"; textBox2.ReadOnly = true; textBox4.BackColor = Color.Yellow; textBox4.ReadOnly = true; } private void button1_Click(object sender, EventArgs e) { if (??) { textBox3.Focus(); } else { int a = int.Parse(textBox3.Text) * int.Parse(textBox2.Text); textBox4.Text = a.ToString(); } } private void button2_Click(object sender, EventArgs e) { textBox3.Clear(); textBox4.Clear(); textBox3.Focus(); } } } 請問??裡要怎麼設 才有辦法讓我在按了button1後 可以執行textBox3.Focus(); 因為如果textBox3裡我沒有打任何數字 就去按button1就會當掉 還是有其他方法可以讓textBox3不輸入任何數字時 按button1也不會當機的 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 122.125.196.27

11/06 01:41, , 1F
(?)..fill textBox3.text=="" try it!!
11/06 01:41, 1F

11/07 00:32, , 2F
在可能產生例外的地方加入 try catch
11/07 00:32, 2F

11/07 02:45, , 3F
if (textBox3.Text ==String.Empty)
11/07 02:45, 3F

11/07 02:46, , 4F
就是說 如果你的textbox3.text是空白的話
11/07 02:46, 4F

11/07 02:48, , 5F
嗚..剛剛看到才發現我跟一樓是同樣意思
11/07 02:48, 5F
文章代碼(AID): #1AyjNJ-3 (C_Sharp)