Solved

Referencing a Mdi Parent Form

Posted on 2004-10-01
10
617 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
  • 2
  • +1
10 Comments
 
LVL 86

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 86

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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
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
 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Suggested Courses

617 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