看板 C_Sharp 關於我們 聯絡資訊
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
wesley412:(?)..fill textBox3.text=="" try it!! 11/06 01:41
leo60037:在可能產生例外的地方加入 try catch 11/07 00:32
iamso1:if (textBox3.Text ==String.Empty) 11/07 02:45
iamso1:就是說 如果你的textbox3.text是空白的話 11/07 02:46
iamso1:嗚..剛剛看到才發現我跟一樓是同樣意思 11/07 02:48