日期:2014-05-17  浏览次数:20774 次

小弟初学C#,就遇到困难了,求大神帮助!
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 Proj2_2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            int a, b, c;
            a = Convert.ToInt16(textBox1.Text);
            b = Convert.ToInt16(textBox2.Text);
            c = a + b;
            textBox3.Text = Convert.ToString(c);
        }
    }
}
这个会报错,这是我按照书上来写的。报错但可以继续执行,可是并不能进行加法计算。求帮助!以下是报错的详细情况:
System.FormatException: 输入字符串的格式不正确。
   在 System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
   在 System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)
   在 System.Int16.Parse(String s, NumberStyles style, NumberFormatInfo info)
   在 System.Convert.ToInt16(String value)
   在 Proj2_2.Form1.Form1_Load(Object sender, EventArgs e) 位置 E:\visual studio 2010\Projects\Proj2-2\Proj2-2\Form1.cs:行号 22
   在 System.Windows.Forms.Form.OnLoad(EventArgs e)
   在 System.Windows.Forms.Form.OnCreateControl()
   在 System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
   在 System.Windows.Forms.Control.CreateControl()
   在 System.Windows.Forms.Control.WmShowWindow(Message& m)
   在 System.Windows.Forms.Control.WndProc(Message& m)
   在 System.Windows.Forms.ScrollableControl.WndProc(Message& m)