好的,我很确定我的代码都是正确的,所以我不确定为什么会出现这个错误。:P 这是我的代码 -->
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace Calculator
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1()); //This is where I am getting the error at
}
}
}
那在我的 program.cs 文件中。这是我的 Form1.cs 文件中的内容。-->
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 Calculator
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btn0_Click(object sender, EventArgs e)
{
txtbox.Text += btn0.Text;
}
private void btn1_Click(object sender, EventArgs e)
{
txtbox.Text += btn1.Text;
}
private void btn2_Click(object sender, EventArgs e)
{
txtbox.Text += btn2.Text;
}
private void btn3_Click(object sender, EventArgs e)
{
txtbox.Text += btn3.Text;
}
private void btn4_Click(object sender, EventArgs e)
{
txtbox.Text += btn4.Text;
}
private void btn5_Click(object sender, EventArgs e)
{
txtbox.Text += btn5.Text;
}
private void btn6_Click(object sender, EventArgs e)
{
txtbox.Text += btn6.Text;
}
private void btn7_Click(object sender, EventArgs e)
{
txtbox.Text += btn7.Text;
}
private void btn8_Click(object sender, EventArgs e)
{
txtbox.Text += btn8.Text;
}
private void btn9_Click(object sender, EventArgs e)
{
txtbox.Text += btn9.Text;
}
private void btnPoint_Click(object sender, EventArgs e)
{
if (txtbox.Text == "0")
{
txtbox.Text = "0.";
}
else
{
txtbox.Text += btnPoint.Text;
}
}
private void btnPlus_Click(object sender, EventArgs e)
{
//Add plus code here
}
private void btnMinus_Click(object sender, EventArgs e)
{
//Add minus code here
}
private void btnTimes_Click(object sender, EventArgs e)
{
//Add times code here
}
private void btnDivide_Click(object sender, EventArgs e)
{
//Add divide code here
}
private void btnEqual_Click(object sender, EventArgs e)
{
//Add equal code here
}
private void btnClear_Click(object sender, EventArgs e)
{
txtbox.Clear();
}
}
}
当我尝试输入一个数字然后输入一个小数时会发生错误。例如,我按“2”,然后按“.”。会发生错误“对象引用未设置为对象的实例”。弹出。感谢您的帮助,谢谢。对不起,如果这是一个愚蠢的错误。:P