Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 623
  • Last Modified:

Referencing a Mdi Parent Form

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
KBanner
Asked:
KBanner
  • 5
  • 2
  • 2
  • +1
1 Solution
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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
 
Arundel_CastleCommented:
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
Arundel_CastleCommented:
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
 
LKearneyCommented:
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
 
Arundel_CastleCommented:
A Globals class is useful in creating applications, I'm pleased that it worked for you. Some points would be nice though :)
0
 
KBannerAuthor Commented:
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
 
Arundel_CastleCommented:
LOL does this mean I don't get any points?
0
 
Arundel_CastleCommented:
Cheers!
0
 
KBannerAuthor Commented:
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 5
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now