I am trying to get my head around OO and C# and although I have searched I can’t see an answer so, hopefully someone here can help.
I have a form (public Form_DaRT_BOM_Main()) and on it a text box (textBox1). These reside in MSVS2010 generated files.
namespace DaRT_BOM
{
public partial class Form_DaRT_BOM_Main : Form
{
public Form_DaRT_BOM_Main()
}
}
I have my own function in Program.cs that resides in
public static class GeneralFunctions
{
}
I am trying to write text into the textbox but can’t see how this should be addressed.
Currently I have:
public static String SplitFile(String FileToSplit)
{
String line;
using (StreamReader reader = new StreamReader(FileToSplit))
{
line = reader.ReadLine();
Form_DaRT_BOM_Main.textBox1 = line;
}
return null;
}
Prior to trying to use the textbox for output I was testing using a MessageBox and that worked okay.
What I get now is a compilation error:
An object reference is required for the non-static field, method, or property
Which suggests I am not addressing the textbox correctly.
Please forgive the Mickey Mouse element but I am still trying to understand… old-dog and new tricks syndrome.
Thanks in anticipation.
Steve.
You need a reference to the form or access textbox1 within the form in some event for example or in the constructor. For example:
If you want to access the form from a static class – make it singleton or make some static property which will hold reference to the actual form.