Results 1 to 8 of 8

Thread: Small MDI / Function question

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2001
    Location
    Lelystad, Netherlands
    Posts
    73

    Small MDI / Function question

    Hi,

    I having some trouble creating/using functions.
    What I thought I could do:
    VB Code:
    1. 'frmMain MDI Parent
    2.     Private Sub mnuFileNew_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuFileNew.Click
    3.         Dim frmDoc As New frmDocument()
    4.         frmDoc.MdiParent = Me
    5.         frmDoc.Show()
    6.     End Sub
    7.  
    8.     Private Sub mnuFileSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuFileSave.Click
    9.         Dim activeChild As Form = Me.ActiveMdiChild
    10.  
    11.         If (Not activeChild Is Nothing) Then
    12.            activeChild.MySaveFunction
    13.         End If
    14.     End Sub
    15.  
    16. 'frmDocument
    17.     Public Function MySaveFunction()
    18.         rtfbox.savefile("d:\test.txt")
    19.     End Function

    But then it keeps saying that MySaveFunction is not a member of 'System.Windows.Forms'.
    What should I do???

    John

  2. #2
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926
    Try this:
    If Not Me.ActiveMdiChild Is Nothing Then
    Dim activeChild As frmDocument = CType(Me.ActiveMdiChild, frmDocument)
    activeChild.MySaveFunction
    End If

    If other forms then frmDocument can also be the ActiveMdiChild, you should include it in a Try block.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Apr 2001
    Location
    Lelystad, Netherlands
    Posts
    73
    Thanx,

    One more thing what if I have a toolbox and I need to enable
    or disable it.
    Like:

    VB Code:
    1. Dim frmTools As frmToolbar
    2.  
    3.     If (frmTools Is Nothing) Then
    4.         Dim frmTools as New frmToolbar
    5.     Else
    6.         frmTools.hide
    7.     End If

    The toolbar isn't an ActiveMDIChild.

    John

  4. #4
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926
    If the toolbox can't be opened more then once, I would suggest to keep the object reference you created when you first opened the form.

    If you only access the toolbox from the MDI parent, you can declare it at module level in the MDI parent.

    Put
    Private frmTools As frmToolbar
    at the module level and not in some click event.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Apr 2001
    Location
    Lelystad, Netherlands
    Posts
    73
    One problem I did that adn used the folowing code:

    VB Code:
    1. Private Sub mnuViewTools_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuViewTools.Click
    2.         If frmTLB Is Nothing Then
    3.             frmTLB = New frmToolbar()
    4.             frmTLB.MdiParent = Me
    5.             frmTLB.Show()
    6.         ElseIf frmTLB.Visible = False Then
    7.             frmTLB.Show()
    8.         Else
    9.             frmTLB.Hide()
    10.         End If
    11.     End Sub

    Now when I use the menu option it shows and hides nicely, but
    if I use the X on the toolbox form it doesn't show anymore.

    John

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Apr 2001
    Location
    Lelystad, Netherlands
    Posts
    73
    Anyone???

  7. #7
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926
    You could check if the form is disposed. If it is, create a new instance.

    eg.
    VB Code:
    1. If frmTLB Is Nothing OrElse frmTLB.IsDisposed Then
    2.             frmTLB = New frmToolbar()
    3.             frmTLB.MdiParent = Me
    4.             frmTLB.Show()
    5.         ElseIf frmTLB.Visible = False Then
    6.             frmTLB.Show()
    7.         Else
    8.             frmTLB.Hide()
    9.         End If

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Apr 2001
    Location
    Lelystad, Netherlands
    Posts
    73
    Thanx that worked

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width