作者mrgyt1030 (Young)
站內C_Sharp
標題Re: [問題] 將文字方塊讀入的文字暫存
時間Sat Apr 10 12:56:39 2010
看了推文
嘗試寫出了以下程式碼:
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
1F:→ james732:你要做的是讀文字方塊 為什麼會用 Console.ReadLine? 04/10 15:04
2F:→ james732:看起來用 int str1 = int.Parse(textBox1.Text); 就好了 04/10 15:05
4F:推 F23ko:=口=||| console.readline不是用在主控台上面的嗎!? 在from 04/10 21:48
5F:→ F23ko:下可以過喔? 04/10 21:48
6F:推 F23ko:如果要讀取文字,請直接讀目標的text 04/10 22:24