MRS
asked on
Get a reference to the start up form
I am currently creating and MDI application with vb.net in VS2010. I would like be able to reference the main start up form in sub windows without having to pass the referencein the constructor or some other method.
Since the main form is also the StartUp Form i was hoping there might be a way to get a reference to that form from the application object.
Does anyone know if there is a way to do this?
Thanks in advance..
Since the main form is also the StartUp Form i was hoping there might be a way to get a reference to that form from the application object.
Does anyone know if there is a way to do this?
Thanks in advance..
ASKER
i was looking for something a little more global then that. Through the course of the application i may need to reference that main form (start up form) from windows that aren't neccessarily child windows.
For instance if i open a dialog window. For the time being i wrote this, i was hoping for a more elegant solution.
For instance if i open a dialog window. For the time being i wrote this, i was hoping for a more elegant solution.
Public Function GetMainForm() As frmMain
Try
For Each frm As Form In My.Application.OpenForms
If frm.GetType Is frmMain.GetType Then
Return frm
End If
Next
Catch ex As Exception
Throw
End Try
End Function
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I never knew that... Well that was easy... :-)
FrmChild.MdiParent=me 'thats if you are referncing if from a menu's click event.
FrmChild.show
or
Woeks in VB 2005
Dim frm as new frmChild
frm.MdiParent=me
frm.show