Save from a MDI Child?

techwiz24

Well-known member
Joined
Jun 2, 2010
Messages
51
Programming Experience
Beginner
I am re-doing part of a GUI for my project, The Windows Alias Generator, and decided to switch to MDI. The child forms consists only of RichTextBox1. Here's the generate routine called when the save is clicked:
VB.NET:
Private Sub SaveAsToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles SaveAsToolStripMenuItem.Click, SaveToolStripButton.Click
        Dim ActiveMDI As Form = Me.ActiveMdiChild
        Dim SaveFileDialog As New SaveFileDialog
        SaveFileDialog.InitialDirectory = Environment.GetEnvironmentVariable("windir")
        SaveFileDialog.Title = "type in an alias name"
        SaveFileDialog.Filter = "Alias Files|*.bat"
        If (SaveFileDialog.ShowDialog(Me) = System.Windows.Forms.DialogResult.OK) Then
            Dim FileName As String = SaveFileDialog.FileName
            awrite32(editor.RichTextBox1.Text, SaveFileDialog.FileName, SaveFileDialog.FileName)
        End If
    End Sub
    End Sub

 Sub awrite32(ByVal command As String, ByVal a_name As String, ByVal path As String)
        If System.IO.File.Exists(path) Then
            Dim result As MsgBoxResult = MsgBox("That alias already exists! Overwrite?", MsgBoxStyle.YesNo)
            If result = MsgBoxResult.Yes Then
                System.IO.File.Delete(path)
                Dim oWrite As New System.IO.StreamWriter(path)
                oWrite.WriteLine("@Echo Off")
                oWrite.WriteLine("REM Generated by amake32")
                oWrite.WriteLine(command)
                oWrite.Close()
                Dim result2 As MsgBoxResult = MsgBox("Alias " + a_name + " successfully applied. Try it out now?", MsgBoxStyle.YesNo)
                If result2 = MsgBoxResult.Yes Then
                    System.Diagnostics.Process.Start("cmd")
                Else
                    'nothing
                End If
            Else
                MsgBox("Alias was not created because an existing file was found and was not overwritten!")
            End If
        Else
            Dim uWrite As New System.IO.StreamWriter(path)
            uWrite.WriteLine("@Echo Off")
            uWrite.WriteLine("REM Generated by amake32")
            uWrite.WriteLine(command)
            uWrite.Close()
            Dim result3 As MsgBoxResult = MsgBox("Alias " + a_name + " successfully applied. Try it out now?", MsgBoxStyle.YesNo)
            If result3 = MsgBoxResult.Yes Then
                System.Diagnostics.Process.Start("cmd")
            Else
                'nothing
            End If
        End If
    End Sub

But because I cannot define richtextbox1.text from the currently active MDI, I cannot use this routine...my question is this: How would I get RichTextBox1.text from the save option in the MDI form?
 
activeMdi.Controls(0).Text
or if you name the RichTextBox "Editor"; activeMdi.Controls("Editor").Text
or if, as you probably do, use multiple instances of a single type form, for example EditorForm; CType(activeMdi, EditorForm).Editor.Text
 
I don't quite get what you are trying to do here.
If what you are trying to do is saving text on a richtextbox control located at mdi child form when you click something at mdi parent, there are plenty ways, such as :
1. Use a static mdi child form, so what you need is just define the control's name as parameter
2. Put the saving routine in the mdi child form, and when user click save button at mdi parent, refer it to/execute the routine located on mdi child
3. and many more
Is that what you are trying to do?
 
Just a quick question... how do you call save routine of child form from parent form. It works fine if you have child form in the same project. But what if child form is in different project and you are referencing it in parent form.

How could we access save method of child form at run time?
 
Back
Top