Solved

Get a reference to the start up form

Posted on 2010-08-12
4
377 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

733 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