I have created an helper function inside my Windows Form source code (is that the right place?), how can I reference variables created elsewhere in the same form source code?
In the following example myVar is declared in myForm and myTextBox is drawn in the designer. Both give as error: "An object reference is required for the non-static field, method, or property".
I know that if I define myVar as static the code would work, but what if I then decide to change its value? As for the text box, changing it to static in the designer file doesn't correct the error..
(I took a look at other questions, but the solution proposed there don't seem to fit in with my code).
myForm.cs
namespace myThing
{
public partial class myForm : Form
{
public int myVar;
public myForm()
{
InitializeComponent();
myVar = 0;
}
static void foo(Point checkPoint, List<Vertex> checkList)
{
int myNumber = myForm.myVar;
myForm.myTextBox.Text = "";
//OR
System.Windows.Forms.TextBox.myTextBox.Text = "";
}
my.Form.Designer.cs
namespace myThing
{
partial class myForm
{
//a bunch of stuff goes here
private System.Windows.Forms.PictureBox myPictureBox;
private System.Windows.Forms.TextBox myTextBox;
}
}