Re: [問題] 將文字方塊讀入的文字暫存

看板C_Sharp作者 (Young)時間16年前 (2010/04/10 12:56), 編輯推噓2(204)
留言6則, 3人參與, 最新討論串2/2 (看更多)
看了推文 嘗試寫出了以下程式碼: public void Sum_Click(object sender, EventArgs e) { string str = Console.ReadLine(); int str1 = int.Parse(str); textBox1.Text = ""; } 編譯可以過 但是執行的時候 數字按完 按"+"的時候 會出現一個警告視窗 ArgumentNullException未處理 請問這要怎麼解決? 附上完整程式碼: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace computer1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void num0_Click(object sender, EventArgs e) { textBox1.Text += "0"; } private void num1_Click(object sender, EventArgs e) { textBox1.Text += "1"; } private void num2_Click(object sender, EventArgs e) { textBox1.Text += "2"; } private void num3_Click(object sender, EventArgs e) { textBox1.Text += "3"; } private void num4_Click(object sender, EventArgs e) { textBox1.Text += "4"; } private void num5_Click(object sender, EventArgs e) { textBox1.Text += "5"; } private void num6_Click(object sender, EventArgs e) { textBox1.Text += "6"; } private void num7_Click(object sender, EventArgs e) { textBox1.Text += "7"; } private void num8_Click(object sender, EventArgs e) { textBox1.Text += "8"; } private void num9_Click(object sender, EventArgs e) { textBox1.Text += "9"; } private void point_Click(object sender, EventArgs e) { textBox1.Text += "."; } public void Sum_Click(object sender, EventArgs e) { string str = Console.ReadLine(); int str1 = int.Parse(str); textBox1.Text = ""; } } } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 125.224.121.11

04/10 15:04, , 1F
你要做的是讀文字方塊 為什麼會用 Console.ReadLine?
04/10 15:04, 1F

04/10 15:05, , 2F
看起來用 int str1 = int.Parse(textBox1.Text); 就好了
04/10 15:05, 2F

04/10 21:37, , 3F
04/10 21:37, 3F

04/10 21:48, , 4F
=口=||| console.readline不是用在主控台上面的嗎!? 在from
04/10 21:48, 4F

04/10 21:48, , 5F
下可以過喔?
04/10 21:48, 5F

04/10 22:24, , 6F
如果要讀取文字,請直接讀目標的text
04/10 22:24, 6F
文章代碼(AID): #1Bm0K9SN (C_Sharp)
文章代碼(AID): #1Bm0K9SN (C_Sharp)