Returning objects from sub-form to main-form
-
I have two forms, when a button is pressed on the main form a second form comes up with a button. This button when pressed brings up the OpenFileDialog. What i want to do is that After i select a file. this result should be returned to the main-form when i close the sub-form. Using VS2012, .NET 4.5, Windows forms App I have googled for many results, but it doesnt seem to work for me. I have tried passing main form instance to sub-form as
SubForm subform = new SubForm(this);
public partial class SubForm : Form
{
private MainForm mainForm;
public SubForm(MainForm mainForm)
{
InitializeComponent();
this.mainForm = mainForm;
}
}and then it was said that i could access objects of mainform from sub-from. But i cant. I also tried making a static main form instance
static class Program
{
public static Form MainForm;/// <summary> /// The main entry point for the application. /// </summary> \[STAThread\] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); MainForm = new Form1(); Application.Run(MainForm); }
}
Still no use, Maybe someone has any other alternative??? Or maybe tell me what might i be doing wrong in the above solutions.