In your file Program.cs
, you can define a globally accessible variable:
static class Program
{
// for external access to Form1 methods
public static Form1 MainForm;
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
MainForm = new Form1(args);
Application.Run(MainForm);
}
}
The static variable MainForm
can then be used to access any public method to Form1
via Program.MainForm.MyMethod()
.
Assuming, you have access to the Form2
object from within Form1
, you can use the Form2
object variable to call Form2
methods out of Form1
methods.
Be aware that you might run into problems when (unknowingly ...) using more than one thread. Read about BeginInvoke.