【发布时间】:2014-07-07 15:02:38
【问题描述】:
我无法找出这段代码中的 2 个错误,有人可以帮帮我吗?
错误 1:Car.Form1 由于其保护级别而无法访问
错误 2:找不到类型或命名空间名称“Point”(您是否缺少 using 指令或程序集引用?
感谢您的帮助!
主类
namespace Car
{
public partial class Form1 : Form
{
int x = 0;
int y = 500;
int turn = 0;
public Form1()
{
InitializeComponent();
}
public void Form1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Right)
{
x += 32;
turn = 1;
}
else if (e.KeyCode == Keys.Left)
{
x -= 32;
turn = 2;
Wheel1.Image.RotateFlip(RotateFlipType.Rotate270FlipNone);
Wheel2.Image.RotateFlip(RotateFlipType.Rotate270FlipNone);
}
else
{
turn = 0;
}
if (x <= -250)
{
x = 1040;
}
else if (x >= 1041)
{
x = -250;
}
}
public void Form1_Load(object sender, EventArgs e)
{
}
}
}
汽车类
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Car
{
public class Car : Form
{
public Car(Form1 form1)
{
form1.Car.Location = new Point(form1.x, form1.y);
}
}
}
【问题讨论】:
-
您知道您正在向表单添加表单吗?
-
您拼错了错误消息。你写的是你认为它所说的,而不是它真正所说的。它抱怨的是 Form1.Car,而不是 Car.Form1。选择好的标识符名称是重要的。
标签: c#