Solved

Referencing a Mdi Parent Form

Posted on 2004-10-01
10
606 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
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

18 Experts available now in Live!

Get 1:1 Help Now