I'm struggling to get a class from a different form without making it static, here's what I want to do:
//First form
public partial class SetupScreen : Form
{
Control myObject;
public Battleship myBattleship;
public SetupScreen()
{
InitializeComponent();
//Create Class Object
myBattleship = new Battleship();
}
}
//Launch second form
public partial class GameScreen : Form
{
Control myObject;
Battleship myBattleship;
Battleship fredBattleship;
public GameScreen()
{
InitializeComponent();
//Get the class
myBattleship = SetupScreen.myBattleship;
}
}
I keep getting the error "an object reference is required for the non-static field, method or property"
I want the class to be accessible by the whole form, not just a single method therefore I don't want to pass it through each time because this is a hassle
I don't want to make the class static since it cannot be erased, how would I go about doing this?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…