I am creating a windows form application using c#. My form has labels, list-boxes and buttons, all of which need to be edited. They are edited from a different class, and further will need the values in the labels to perform other logic.
My problem is accessing these controls from other classes. I tried making an instance of the form and using it like this:
Form frm = new Form();
myVar = frm.lblMylabel.Text;
However, using a breakpoint, I followed the code, and it loops between the above instance being created, and the start of the Form code, which calls the class again where the instance was created.
I have tried to find the answer online, however they don't seem applicable to what I am trying to do, and whilst I am unsure how to do it, they appear to be overly complex. So, my question it: is there a relatively simple way to be able to access values and edit values from controls in a form from another class?
Thanks in advance.
EDIT - Breakpoint starts at Point 3, '=new Form();'.
Loops to Point 1.
Point 2 calls GamePlay().
Reaches Point 3 and loop restarts.
public partial class frmGame : Form //Point 1
{
public frmGame()
{
InitializeComponent();
Game.GamePlay(); //Point 2
}
class Game{
public static void GamePlay()
{
frmGame form = new frmGame(); //Point 3
form.lstPrevious1.Items.Add("Item Number");
}
}