C#中的帮助(无法找到命名空间Form1) [英] Help in C# (Namespace Form1 could not be found)
本文介绍了C#中的帮助(无法找到命名空间Form1)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好
我是c#的新手,想要创建简单的计算器( Windows窗体应用程序)
i am new to c# and want to create simple calculator (Windows Form application)
但是当我尝试运行它时,它说 &"无法找到类型或命名空间名称'Form1'
(您是否缺少using指令或汇编引用?)"
but when i try to run it , it says "The type or namespace name 'Form1' could not be found (are you missing a using directive or an assembly reference?)"
这是我使用System创建计算器的按钮和教科书后的代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Calculator
{
public partial class Calculator : Form
{
double FirstNumber;
string Operation;
public Calculator()
{
InitializeComponent();
}
private void button3_Click(object sender, EventArgs e)
{
if (textBox1.Text == "0" && textBox1.Text != null)
{
textBox1.Text = "3";
}
else
{
textBox1.Text = textBox1.Text + "3";
}
}
private void n1_Click(object sender, EventArgs e)
{
if (textBox1.Text == "0" && textBox1.Text != null)
{
textBox1.Text = "1";
}
else
{
textBox1.Text = textBox1.Text + "1";
}
}
private void n2_Click(object sender, EventArgs e)
{
if (textBox1.Text == "0" && textBox1.Text != null)
{
textBox1.Text = "2";
}
else
{
textBox1.Text = textBox1.Text + "2";
}
}
private void n4_Click(object sender, EventArgs e)
{
if (textBox1.Text == "0" && textBox1.Text != null)
{
textBox1.Text = "4";
}
else
{
textBox1.Text = textBox1.Text + "4";
}
}
private void n5_Click(object sender, EventArgs e)
{
if (textBox1.Text == "0" && textBox1.Text != null)
{
textBox1.Text = "5";
}
else
{
textBox1.Text = textBox1.Text + "5";
}
}
private void n6_Click(object sender, EventArgs e)
{
if (textBox1.Text == "0" && textBox1.Text != null)
{
textBox1.Text = "6";
}
else
{
textBox1.Text = textBox1.Text + "6";
}
}
private void n7_Click(object sender, EventArgs e)
{
if (textBox1.Text == "0" && textBox1.Text != null)
{
textBox1.Text = "7";
}
else
{
textBox1.Text = textBox1.Text + "7";
}
}
private void n8_Click(object sender, EventArgs e)
{
if (textBox1.Text == "0" && textBox1.Text != null)
{
textBox1.Text = "8";
}
else
{
textBox1.Text = textBox1.Text + "8";
}
}
private void n9_Click(object sender, EventArgs e)
{
if (textBox1.Text == "" && textBox1.Text != null)
{
textBox1.Text = "9";
}
else
{
textBox1.Text = textBox1.Text + "9";
}
}
private void n0_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + "0";
}
private void bad_Click(object sender, EventArgs e)
{
FirstNumber = Convert.ToDouble(textBox1.Text);
textBox1.Text = "0";
Operation = "+";
}
private void bsub_Click(object sender, EventArgs e)
{
FirstNumber = Convert.ToDouble(textBox1.Text);
textBox1.Text = "0";
Operation = "-";
}
private void bmul_Click(object sender, EventArgs e)
{
FirstNumber = Convert.ToDouble(textBox1.Text);
textBox1.Text = "0";
Operation = "*";
}
private void bdiv_Click(object sender, EventArgs e)
{
FirstNumber = Convert.ToDouble(textBox1.Text);
textBox1.Text = "0";
Operation = "/";
}
private void bc_Click(object sender, EventArgs e)
{
textBox1.Text = "0";
}
private void ndot_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + ".";
}
private void nequal_Click(object sender, EventArgs e)
{
double SecondNumber;
double Result;
SecondNumber = Convert.ToDouble(textBox1.Text);
if (Operation == "+")
{
Result = (FirstNumber + SecondNumber);
textBox1.Text = Convert.ToString(Result);
FirstNumber = Result;
}
if (Operation == "-")
{
Result = (FirstNumber - SecondNumber);
textBox1.Text = Convert.ToString(Result);
FirstNumber = Result;
}
if (Operation == "*")
{
Result = (FirstNumber * SecondNumber);
textBox1.Text = Convert.ToString(Result);
FirstNumber = Result;
}
if (Operation == "/")
{
if (SecondNumber == 0)
{
textBox1.Text = "Cannot divide by zero";
}
else
{
Result = (FirstNumber / SecondNumber);
textBox1.Text = Convert.ToString(Result);
FirstNumber = Result;
}
}
}
}
}
推荐答案
&"找不到类型或命名空间名称'Form1'(您是否错过了使用指令或汇编参考?)"
命名空间 计算器
您将命名空间名称更改为上面的名称,您需要更改它回到 Form1,因为有很多内部事物引用了Form1的名称空间名称。
You changed the namespace name to the above, and you need to change it back to Form1, becuase there are a lot of internal things referencing the namepace name of Form1.
这篇关于C#中的帮助(无法找到命名空间Form1)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文