Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Referencing a Mdi Parent Form

Posted on 2004-10-01
10
Medium Priority
?
622 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 800 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
Independent Software Vendors: 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!

 
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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
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.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

688 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