作者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