I'm a bit confused during my transition from VB to c# - I have a UserForm that's started from the Main point:
static class Program
{
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new AwesomeForm());
}
}
On this form I've got a label, Label1, but I can't access it from another class (AwesomeForm.Label1
doesn't exist in intellisense) - it won't find Label1 or in fact any of the public methods in the form; I tried to make a method on the AwesomeForm
with a public accessor:
public void UpdateMe(string TheMessage)
{
this.Label1.Text = TheMessage;
}
In VB I would simply just use the name of the form and the public method (AwesomeForm.UpdateMe("Hi!")
I gather this has got something to do with the Application.Run(new AwesomeForm());
creating an instance of AwesomeForm
and I thought I may be able to access the instance with public Form MyAwesomeForm = Application.OpenForms[0];
giving me MyAwesomeForm
to play with, but while that line doesn't error, I still don't get a list of methods in intellisense and it doesn't compile when I try to use Form.UpdateMe()
I tried declaring a variable for it, public AwesomeForm MyAwesomeForm = Application.OpenForms[0];
but that didn't work...
Where am I going wrong?! How can I tell a class somewhere else to change something in the start-up form?
Can I just put a variable name somewhere in the line Application.Run(new AwesomeForm());
e.g. Application.Run(Wow new AwesomeForm()); and then I can get the first instance of an AwesomeForm?