Re: [問題] 將文字方塊讀入的文字暫存
看了推文
嘗試寫出了以下程式碼:
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
04/10 15:04, 1F
→
04/10 15:05, , 2F
04/10 15:05, 2F
→
04/10 21:37, , 3F
04/10 21:37, 3F
推
04/10 21:48, , 4F
04/10 21:48, 4F
→
04/10 21:48, , 5F
04/10 21:48, 5F
推
04/10 22:24, , 6F
04/10 22:24, 6F
討論串 (同標題文章)
完整討論串 (本文為第 2 之 2 篇):