Parent Form interacting with Child Form

K

Ken Powers

Hello Everyone,

I need help on a small problem I'm working with. VB.NET

I have an array of child forms

Public frmChild(10) as form

I uses the array of child forms with a toolbar on the parent.

Now when a menu item on the parent was click it would use the array of forms
like this.

Private Sub miUAEDUtility_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles miUAEDUtility.Click
frmChild(1) = New frmUtility
frmChild(1).MdiParent = Me
frmChild(1).Show()
End Sub

In each form that use the child form is a Public Writeonly Property called
Navigate

Public WriteOnly Property Navigate()
Set(ByVal Value)
Select Case Value
Case "Print"
Case "First"
Case "Previous"
Case "Next"
Case "Last"
Case "Add"
Case "Update"
Case "Delete"
Case "Close"
End Select
End Set
End Property

Now what I want is when a button on the toolbar is clicked to send a string
to the navigate property of the child form. In vb it work like this.

ActForm being an integer that the child form insert thier id

frmChild(ActForm).Count
If ActForm > 0 Then
frmChild(ActForm).Navigate = Button.Key
End If

Hope everyone understands

Ken
 
K

Ken Powers

I've got it to work, but I was hoping for somthing a little more dymanic.

Private Sub ToolBar1_ButtonClick(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.ToolBarButtonClickEventArgs) Handles
ToolBar1.ButtonClick
If ActForm > 0 Then
Dim activeChild As Form = Me.ActiveMdiChild
Select Case activeChild.Name
Case "frmPreview"
CType(activeChild, frmPreview).Navigate =
e.Button.Text.ToString
Case "frmUtility"
CType(activeChild, frmUtility).Navigate =
e.Button.Text.ToString
Case "frmSetup"
CType(activeChild, frmSetup).Navigate =
e.Button.Text.ToString
Case "frmBillDeter"
CType(activeChild, frmBillDeter).Navigate =
e.Button.Text.ToString
Case "frmRate"
CType(activeChild, frmRate).Navigate =
e.Button.Text.ToString
Case "frmAdjustments"
CType(activeChild, frmAdjustments).Navigate =
e.Button.Text.ToString
Case "frmDataChange"
CType(activeChild, frmDataChange).Navigate =
e.Button.Text.ToString
End Select
End If
End Sub
 
H

Herfried K. Wagner [MVP]

Hello,

Ken Powers said:
Is there anyway to get around having to hard code in the form names?

Do all of the form classes define their own Navigate property or is this
property inherited from a common base class? Using a common base class will
make work easier.

For example, you can create a form class A (inherits from
System.Windows.Forms.Form) which defines a Navigate property. All other
forms which need this property, derive from class A. You can use this code
to set the form's Navigate property for _all_ form classes which inherit
from A:

\\\
DirectCast(ActiveChild, A).Navigate = True
///

If you want to avoid using a common base class, there is a way using
reflection, but I would not recomment that. Maybe you want to have a look
at VB .NET's CallByName method.

Regards,
Herfried K. Wagner
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top