Solved

Referencing a Mdi Parent Form

Posted on 2004-10-01
10
607 Views
Last Modified: 2012-06-21
Hi,

I am trying to change a statusBar at the bottom of my Parent Form in vb.net

Have 1 MdiParent form and several Child forms.

The MdiParent form is setup in vb.net as the "StartUp object". Therefore, you don't need to create an instance of the form, whereas with the mdi child forms you create an instance of the form, and then show that form as below

Dim m_Frm_Search As New Frm_Search
m_Frm_Search.Show()

To reference this form you simply m_Frm_Search.whatever

I cannot seem to get the reference to the controls on the Mdi Parent main form.

Can anybody help??
Many thanks.
Kerrin
0
Comment
Question by:KBanner
  • 5
  • 2
  • 2
  • +1
10 Comments
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 12201673
When you create your child forms, set the MdiParent property:

    Dim m_Frm_Search As New Frm_Search
    m_Frm_Search.MdiParent = Me
    m_Frm_Search.Show()


Now from in m_Frm_Search you should be able to use:

    Me.MdiParent.someControlName.Text = ""

~IM
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 12201689
You may have to cast your reference to the type of your parent form.  If your MDI Parent is Form1 for example you can do:

    Dim p As Form1
    p = CType(Me.MdiParent, Form1)
    p.someControlName.Text = ""

~IM
0
 
LVL 3

Accepted Solution

by:
Arundel_Castle earned 200 total points
ID: 12201733
You can define a class called Globals that has public access and shared members and place a reference to your Parent form to shared variable there. You don't have to create an object just reference the globals class.

Public Class Globals
    Public Shared midiRef As myMidiForm
End Class

Private Sub myMidiForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Globals.midiRef = Me
End Sub
0
 
LVL 3

Expert Comment

by:Arundel_Castle
ID: 12201746
Then you can always access the midiform from anywhere in your application by using the globals class. You just have to reference the globals class and not create a new object.
0
 

Expert Comment

by:LKearney
ID: 12216053
Hi Guys,

first off, genuinely, thanks you very much for posting suggestions.

 Idle_Mind - gave your method a try and was coming up with "instance of an object" error. Probably just overlooking some small issue

Arundel - created a class as below

Public Class clsMainMenu
    Public Shared m_Frm_MainMenu As Frm_MainMenu
End Class

Can now reference using clsMainMenu.m_Frm_MainMenu.controlname where controlname is the control on the mdi parent form (Frm_MainMenu)

Works fine thank you.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 3

Expert Comment

by:Arundel_Castle
ID: 12216073
A Globals class is useful in creating applications, I'm pleased that it worked for you. Some points would be nice though :)
0
 

Author Comment

by:KBanner
ID: 12216088
Guys,

Sorry I was using a collegues id on EE. He left himself logged in and I simply thought it was myself.  Hence why "LKearney" seems to be appearing as me.

The above message should have been the comments of the author of the post "KBanner"

sorry for confusion

0
 
LVL 3

Expert Comment

by:Arundel_Castle
ID: 12216102
LOL does this mean I don't get any points?
0
 
LVL 3

Expert Comment

by:Arundel_Castle
ID: 12216138
Cheers!
0
 

Author Comment

by:KBanner
ID: 12216156
Hi Arundel,

Sorry mate, had to log off and log back in again to allocate the points. What a pain!! I'm going to ban him from using my PC.

Points should have been allocated now.

Thanks again!!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

867 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

16 Experts available now in Live!

Get 1:1 Help Now