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 : For
you must use singleton pattern. so your code must be like this:
//First form
public partial class SetupScreen : Form
{
public static SetupScreen setupScreenFrm;
Control myObject;
public Battleship myBattleship;
public SetupScreen()
{
setupScreenFrm=this;
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
SetupScreen ssFrm=SetupScreen.setupScreenFrm;
myBattleship = ssFrm.myBattleship;
}
}
and first of all, in the start of your app, create an instant of SetupScreen form.
now you can access to SetupScreen in anywhere.