错误:汽车.Form1是不可访问的,因为它的保护级别是c#
本文关键字:因为 保护 访问 汽车 Form1 错误 | 更新日期: 2023-09-27 18:11:52
我不能在这个代码中找出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.Location
,我相信Car
是对您的表单的一些控制。默认情况下,所有控件都是private
,并且在表单类之外不可见。快速解决方案:在设计器中选择Car
控件,然后进入其属性。找到属性Modifiers
并将其更改为public
。这将为控件生成公共字段,但也会破坏表单的封装。最好在表单上创建移动汽车到新位置的方法。比如:
公共void MoveCar(点位置){的车。Location =位置;}
Point
在System.Drawing
命名空间中声明