|
-
Jun 21st, 2002, 02:48 AM
#1
Thread Starter
Lively Member
Small MDI / Function question
Hi,
I having some trouble creating/using functions.
What I thought I could do:
VB Code:
'frmMain MDI Parent
Private Sub mnuFileNew_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuFileNew.Click
Dim frmDoc As New frmDocument()
frmDoc.MdiParent = Me
frmDoc.Show()
End Sub
Private Sub mnuFileSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuFileSave.Click
Dim activeChild As Form = Me.ActiveMdiChild
If (Not activeChild Is Nothing) Then
activeChild.MySaveFunction
End If
End Sub
'frmDocument
Public Function MySaveFunction()
rtfbox.savefile("d:\test.txt")
End Function
But then it keeps saying that MySaveFunction is not a member of 'System.Windows.Forms'.
What should I do???
John
-
Jun 21st, 2002, 03:00 AM
#2
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.
-
Jun 21st, 2002, 05:31 AM
#3
Thread Starter
Lively Member
Thanx,
One more thing what if I have a toolbox and I need to enable
or disable it.
Like:
VB Code:
Dim frmTools As frmToolbar
If (frmTools Is Nothing) Then
Dim frmTools as New frmToolbar
Else
frmTools.hide
End If
The toolbar isn't an ActiveMDIChild.
John
-
Jun 21st, 2002, 05:49 AM
#4
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.
-
Jun 21st, 2002, 07:01 AM
#5
Thread Starter
Lively Member
One problem I did that adn used the folowing code:
VB Code:
Private Sub mnuViewTools_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuViewTools.Click
If frmTLB Is Nothing Then
frmTLB = New frmToolbar()
frmTLB.MdiParent = Me
frmTLB.Show()
ElseIf frmTLB.Visible = False Then
frmTLB.Show()
Else
frmTLB.Hide()
End If
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
-
Jun 25th, 2002, 01:00 PM
#6
Thread Starter
Lively Member
-
Jun 25th, 2002, 01:40 PM
#7
You could check if the form is disposed. If it is, create a new instance.
eg.
VB Code:
If frmTLB Is Nothing OrElse frmTLB.IsDisposed Then
frmTLB = New frmToolbar()
frmTLB.MdiParent = Me
frmTLB.Show()
ElseIf frmTLB.Visible = False Then
frmTLB.Show()
Else
frmTLB.Hide()
End If
-
Jun 25th, 2002, 03:14 PM
#8
Thread Starter
Lively Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|