Solved

Get a reference to the start up form

Posted on 2010-08-12
4
368 Views
Last Modified: 2013-11-26
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..
0
Comment
Question by:MRS
  • 2
  • 2
4 Comments
 
LVL 12

Expert Comment

by:NormanMaina
ID: 33423762
IN VB 2008

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
0
 

Author Comment

by:MRS
ID: 33423838
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.
   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

Open in new window

0
 
LVL 12

Accepted Solution

by:
NormanMaina earned 500 total points
ID: 33423897
in vb 2008 all you need to do is call the form dicrectly from any other form.

ie frmmain.text="Success"
0
 

Author Closing Comment

by:MRS
ID: 33423908
I never knew that... Well that was easy... :-)
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now