I cant figure out 2 errors in this code can someone help me please?
error 1: Car.Form1 is inaccessible due to its protection level
error 2: The type or namespace name 'Point' could not be found (are you missing a using directive or an assembly reference?
Thanks for the help!
Main class
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)
{
}
}
}
car class
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);
}
}
}
According to form1.Car.Location
I believe Car
is some control on your form. By default all controls are private
and not visible outside of form class. Fast solution: select your Car
control in designer, and go to its properties. Find property Modifiers
and change it to public
. That will generate public field for your control, but it will also break encapsulation of your form. Better create method on form for moving car to new location. Something like:
public void MoveCar(Point location) { Car.Location = location; }
Point
is declared in System.Drawing
namespace.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.