Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how do you refer to the parent form, from the child form in VB.NET 2

Status
Not open for further replies.

Ross1811

MIS
Oct 1, 2004
122
0
0
US
Hello everyone,

Got a quick question, how do you refer to the parent form, from the child form in VB.NET.

Basically I do not want to make another form (the same one twice) such as
Dim a as New Frmmain
a.Hide()
a.Show()

I just want to hide and show frmMain from another form,
I want to just call frmMain.Hide and show without recreating another, any ideas????? Also maybe is it something to do with Public Class frmMain on the original form??????????????????????


Thanks,
Ross
 
Hey man, If you look in my profile..I believe I asked the same question a while back...and I got a great piece of info from someone....it was a function that allowed you to do that easily...kinda like you used to be able to do back in VB6
 
It says when I look at your profile ...And will be back shortly. Thank you for your patience while we work to improve the site.
 
well man...it was from experts-exchange..not here. sorry about that...but it this what you're trying to do? Let me know.. i Know it seems long winded..but i guess this is the way you have to do it for now..


Here is the post:


And here is the code.


This is what I use to find a control recursively looking through other container controls:

Public Function FindControlByName(ByVal containerParent As Object, ByVal nameSearch As String) As Control

' Description:
' Starting with the top-level container, search through each control looking for a control
' with the specified name. If the current control has children controls, such as a GroupBox, then
' recursively call this routine to search for the control in each container.

' VB.NET is different in this regard from VB6, where Me.Controls in VB6 contained all the controls
' for the form, and in VB.NET it contains only the top-level controls.

Dim foundControl As Control

Try

For Each controlCurrent As Control In containerParent.Controls

If controlCurrent.Controls.Count > 0 Then

' The current control owns other controls, so search through the
' controls for that container for the specified control name.
foundControl = FindControlByName(controlCurrent, nameSearch)
End If

' Control not found from the container search?
If foundControl Is Nothing Then

' Control matched by name?
If controlCurrent.Name = nameSearch Then

' Return a reference to the control to the caller.
foundControl = controlCurrent

' Don't go any further, since the control was found.
Exit For

End If ' Control matched by name?

Else

' Don't go any further, since the control was found on the container.
Exit For

End If ' Control not found from the container search?

Next controlCurrent

Finally

End Try

Return foundControl

End Function 'FindControlByName'

Bob
 
I am not trying to find a control on the parent form I am trying to just call it from the child form. Such as

Dim a as New Frmmain '(this creates two, the parent and this one)
a.Hide()
a.Show()

I just need to call it from the child without reproducing the parent. Such as frmMain.hide
frmMain.Show --> this will not create the uneeded duplicate

Ross
 
I am kinda lost with

'In frmMain
Public Shared SingleInstance As FrmMain = New FrmMain


'Outside frmMain
frmMain.SingleInstance.Hide

I put that in my code and it does not like it from the get go but I believe it is something like this. Do I replace Public Class frmMain at the begining of the form? If so Public Shared SingleInstance As FrmMain = New FrmMain creates an error, where should I be placing it?
 
Put
Public Shared SingleInstance As FrmMain = New FrmMain

inside the class where you would put ANY class level variables.

Public Class FrmMain
Inherits System.Windows.Forms.Form

Public Shared SingleInstance As FrmMain = New FrmMain


Forms/Controls Resizing/Tabbing
Compare Code
Generate Sort Class in VB
Check To MS)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top