.NET ::Accessing MDI form controls from child forms or other methods
I remember in VB6 days, it was damn easy to access other form controls by writing formName.ControlName.Property.This is something which is not possible in VB.NET. I tried traditional methods to access MDI form controls but got Object Reference error. Then I found solution by using DirectCast() method to assign values to MDI's controls at run time. So If you want to set statusbar on MDI from Child form, just write the following line:
DirectCast(Me.MdiParent, MainForm).StatusBar1.Text = "My Statusbar Value"
Here MainForm is the name of your MDI Form
As it's quite clear, here ME means the form where this code exist so if you are calling on Click Event of any form, use Me.MdiParent as first parameter and MainForm(MDI Form's)'s name as 2nd parameter. That's it!
If you want to access MDI controls from some other method in any other class then you can simply use any variable of type Form to perform the task since it just needs ANY child's form MDI property to perform the task. For example:
DirectCast(myChildForm.MdiParent, MainForm).StatusBar1.Text = "My Statusbar Value"