В момент открытия дочерней формы ей присваивается номер документа. Это нормально, но я хочу затем изменить номер документа, чтобы показать имя, под которым файл был сохранен. Я попытался создать функцию CurrentFile, но она работала только для форм SDI, а не форм MDI, и отображалась только в родительской форме.
Private Sub NewToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NewToolStripMenuItem.Click
' File, New command
NewChildCount += 1
Dim NewChild As New Document()
NewChild.MdiParent = Me
NewChild.Text = "Document " & NewChildCount.ToString
NewChild.Show()
End Sub
Private Sub OpenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenToolStripMenuItem.Click
' File, Open menu command.
Dim sr As StreamReader
OpenFileDialog1.FileName = ""
OpenFileDialog1.Filter = "Text Files *.txt | *.txt"
If OpenFileDialog1.ShowDialog = DialogResult.OK Then
Try
sr = File.OpenText(OpenFileDialog1.FileName)
Dim newDoc As New Document()
newDoc.RichTextBox1.Text = sr.ReadToEnd
sr.Close()
newDoc.Text = OpenFileDialog1.FileName
newDoc.MdiParent = Me
newDoc.Show()
newDoc.isNamed = True
'CurrentFileName()
' Move cursor to the start of the document.
With newDoc.RichTextBox1
.Select()
.SelectionStart = 0
.SelectionLength = 0
End With
Catch ex As Exception
MsgBox("There was an error opening the file.")
End Try
End If
End Sub
Private Sub SaveDocument(ByVal doc As Document, ByVal FileName As String)
Try
Dim sw As New StreamWriter(FileName)
sw.Write(doc.RichTextBox1.Text)
sw.Close()
doc.isNamed = True
doc.isDirty = False
Catch ex As Exception
MsgBox("There was an error saving the file.")
End Try
End Sub