Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 2005 > Pro Visual Basic 2005
|
Pro Visual Basic 2005 For advanced Visual Basic coders working in version 2005. Beginning-level questions will be redirected to other forums, including Beginning VB 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro Visual Basic 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 21st, 2006, 03:30 AM
Registered User
 
Join Date: Sep 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Reference between child window of MDI in vb 2005

The interface of my MDI Program:

My MDI program code source:
¡® This is the MDI main window (the container), use it¡¯s menu option to open the child window as many as you want.
Public Class frmMdi

    Private Sub mNewSub1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mNewSub1.Click
        Dim f As New frmSub1
        f.MdiParent = Me
        f.Show()
    End Sub

    Private Sub mNewSub2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mNewSub2.Click
        Dim f As New frmSub2
        f.MdiParent = Me
        f.Show()
    End Sub
End Class

¡® Child window 1. From here, want to call the function or excute the procedure in child window 2.
Public Class frmSub1

    ' Call the function named fSum in child window 2.
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        For Each f As Form In frmMdi.MdiChildren
            If TypeOf f Is frmSub2 Then ¡® see Note
                ' I want to call fSum in f, something like this: textbox1.text=f.fSum(4)
                ' but it is no fSum object in f. How can explore the fSum object in frmSub2?
            End If
        Next
    End Sub
¡®Note: In practice, I have to use another IF statement within this IF statement to locate one of the frmSub2

    ' Excute the procedure named pSum in child window 2.
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        ' Same problem, how to explore the pSum object in frmSub2 and can excute it here.
    End Sub
End Class

¡® Child window 2. have the function and procedure being called or excuted by child window 1.
Public Class frmSub2

    Friend Sub pSum(ByVal j As Integer)
        Dim i As Integer, sum As Integer

        For i = 1 To j
            sum = sum + i
        Next
        TextBox1.Text = sum
    End Sub

    Friend Shared Function fSum(ByVal j As Integer) As Integer
        Dim i As Integer

        For i = 1 To j
            fSum = fSum + i
        Next
    End Function

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        TextBox1.Text = fSum(Val(TextBox1.Text))
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Call pSum(TextBox1.Text)
    End Sub
End Class








Similar Threads
Thread Thread Starter Forum Replies Last Post
Displaying MDI Child Form Menus with MDI Parent ashu_from_india Pro VB 6 3 June 10th, 2008 11:01 PM
Controlling MDI child form from MDI parent panel LuxCoder VB.NET 2002/2003 Basics 7 April 11th, 2007 02:38 PM
Again: Reference between child window of MDI ly_he Pro Visual Basic 2005 1 September 25th, 2006 09:40 PM
Opening MDI Child on Button Click of MDI Child Sachin Shinde Visual Studio 2005 0 June 8th, 2006 05:05 AM
Mdi child window minimizes vsramiya Pro VB 6 2 October 28th, 2005 07:32 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.