iam new to C#
i got some problem, i am create some picturebox in the Form1 through Form.cs[Design]
i want to accessing the picture box from Form1
so i have to create an object on other class to access Form1.picturebox1
but i can get it right, can some one help me
namespace RaceGame{
class Greyhound
{
Form1 runner;
public int StartingPosition = 13;
public int RacetrackLength = 420;
public PictureBox MyPictureBox = null;
public int Location = 0;
public Random Randomizer;
public void Run()
{
runner.pictureDog1.Location = new Point(13, 100);
}
}
this is Form1
namespace RaceGame{public partial class Form1 : Form
{
Greyhound racing = new Greyhound();
public Form1()
{
InitializeComponent();
}
private void raceButton_Click(object sender, EventArgs e)
{
racing.Run();
}
}
}
Based on the code you’ve provided, your Form1 or ‘runner’ isn’t being assigned.
You have two options –
1) make your runner public like so
public Form1 runner;this will allow you to (in your form, not your class) assign the form to this property
the other option is to use a constructor, like so –
this will pass the form into the greyhound class for you to access, then in your form code –
EDIT:
based on the form code you gave –
and the Greyhound class