Ok So I am trying to save text from a textbox to a rtf file. The Saves Text would come from the active mdi Child. However I can not figure out how to Save using active child just calling the actual form name. Below is my code so far.

Private Sub SaveAsToolStripMenuItem_Click(ByVal sender As System.Object,
                ByVal e As System.EventArgs) Handles SaveAsToolStripMenuItem.Click
        Try
            Dim myfile As String
            Dim saveFileDialog1 As New SaveFileDialog()
            myfile = ActiveMdiChild.Text
            saveFileDialog1.OverwritePrompt = True
            saveFileDialog1.FileName = myfile
            saveFileDialog1.Filter = "Rich Text Format (*.rtf)|*.rtf|All files (*.*)|*.*"
            saveFileDialog1.ShowDialog()

            If saveFileDialog1.FileName = "" Then
                Exit Sub
            End If
            ' this part saves the file
            FileSystem.FileOpen(1, saveFileDialog1.FileName, OpenMode.Output)
            FileSystem.Print(1, Cant figure out )'this is where i need the help!!
            FileSystem.FileClose(1)
        Catch
            MessageBox.Show("No File To Save Exist", "Save Error", MessageBoxButtons.OK, _
                           MessageBoxIcon.Error)
        End Try

    End Sub

This is how I create new windows from the parent

Private windowNumber As Integer = 0 ' for display in title bar

    Private Sub NewToolStripMenuItem_Click(ByVal sender As System.Object,
                ByVal e As System.EventArgs) Handles NewToolStripMenuItem.Click
        windowNumber += 1
        Me.LayoutMdi(MdiLayout.ArrangeIcons)
        Dim appEditorForm As New textEditorForm


        appEditorForm.MdiParent = Me
        appEditorForm.Text = "Window " & windowNumber ' set title
        appEditorForm.Show()


    End Sub

Thanks In advance

See if this helps.

Private Sub SaveAsToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveAsToolStripMenuItem.Click
        If Not Me.ActiveMdiChild Is Nothing Then '// check if Form available.
            MsgBox(Me.ActiveMdiChild.Name) '// get .Name of Active Form.
        End If
    End Sub

I'm not sure how this helps. i dont need the name of the child. i need to access the textbox contents inside the active child.

>>However I can not figure out how to Save using active child just calling the actual form name.

In any case, if just one control on the MdiForm, see if this helps.

If Not Me.ActiveMdiChild Is Nothing Then
            MsgBox(Me.ActiveMdiChild.Controls(0).Text)
        End If
commented: Lead me in right direction , thanks +1

This is what i came up with... just thought I'd let you know how i did it

'===========================================
    '== SaveAsToolStripMenuItem_Click         ==
    '===========================================
    'Author: Tim Newport
    'Date: 20-Jan-2011
    'Purpose: Save Info in active window
    Private Sub SaveAsToolStripMenuItem_Click(ByVal sender As System.Object,
                ByVal e As System.EventArgs) Handles SaveAsToolStripMenuItem.Click
        Dim myfile As String
        Dim saveFileDialog1 As New SaveFileDialog()
        myfile = ActiveMdiChild.Text
        With saveFileDialog1
            .Title = "Save As Dialog"
            .OverwritePrompt = True
            .FileName = myfile
            .Filter = "Rich Text Format (*.rtf)|*.rtf|All files (*.*)|*.*"
            .FilterIndex = 1
            .RestoreDirectory = True
            .ShowDialog()
        End With

        Try
            Dim fileText As String
            Dim filePath As String
            Dim childForm As New textEditorForm
            childForm = Me.ActiveMdiChild
            If saveFileDialog1.FileName = "" Then
                Exit Sub
            End If
            filePath = System.IO.Path.Combine(My.Computer.FileSystem.SpecialDirectories.MyDocuments,
                                              saveFileDialog1.FileName)
            ' fill contents of file
            fileText = childForm.txtEditor.Text
            My.Computer.FileSystem.WriteAllText(filePath, fileText, False)

            FileSystem.FileClose(1)
        Catch
            MessageBox.Show("No File To Save Exist", "Save Error", MessageBoxButtons.OK, _
                           MessageBoxIcon.Error)
        End Try

    End Sub
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.