Just some short background information: I have been coding VB.Net and PHP for at least two years (self-taught), so please excuse me if my terminology and coding habits aren't exactly top-notch. I will improve based on your comments!
Ok so I currently have a login form that is set as the startup object in Program.cs. This is where I make a new instance of the login form and pass it by reference to the FormInstances class (in Misc.cs).
using System;
using System.Windows.Forms;
namespace Blah{
class Program{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.SetCompatibleTextRenderingDefault(false);
Application.EnableVisualStyles();
var LoginFRM = new Login();
LoginFRM.ShowDialog();
if(LoginFRM.LoginSuccessful == true) {
FormInstances.LoginForm = LoginFRM;
Application.Run(new MainForm());
}else{
Application.Exit();
}
}
}
}
And this is my code in Misc.cs:
namespace Blah{
public static class FormInstances {
public static Form LoginForm;
}
public class Misc{
FormInstances.LoginForm.txtTest.text = "test";
}
}
However I am getting this error:
'Form' does not contain a definition for 'txtText' and no extension method 'txtText' accepting a first argument of type 'Form' could be found (are you missing a using directive or an assembly reference?)
How do I fix this error, are there easier ways to achieve my goal?
The base class Form doesn't contain a textbox named 'txtText', you need to declare the exact type of the form, not the generic base class
namespace Blah{
public static class FormInstances {
public static Login LoginForm;
}
public class Misc{
FormInstances.LoginForm.txtTest.text = "test";
}
}
As a side note, why do you need to keep the whole Login form stored? If you just need to know if your user has been logged or not then you could just store a boolean variable obtained from the property LoginSuccessful