MDI Forms and Child Forms
-
I would appreciate it if some one could help me. I don't know how to write the code to save or save as in my forms. Here is the code that I have so far. Note that my parent form has file(new,open, save, save as, close) on it. I have already done the new code and I have been searching through the help files of .Net for 2 hours now with no help what so ever. Also please note that opion strict is set to on. Public Class frmMDI Inherits System.Windows.Forms.Form Dim counter As Integer = 1 Private Sub frmMDI_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Dim j As Integer 'For j = 1 To 3 ' Dim frmDocForm As New frmChild ' frmDocForm.MdiParent = Me ' frmDocForm.Show() 'Next End Sub Private Sub ToolBar1_ButtonClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolBarButtonClickEventArgs) Handles ToolBar1.ButtonClick If e.Button.Tag Is "new" Then NewFile() ElseIf e.Button.Tag Is "open" Then ElseIf e.Button.Tag Is "save" Then ElseIf e.Button.Tag Is "bold" Then Dim frmActiveChild As frmChild = Me.ActiveMdiChild If (Not frmActiveChild Is Nothing) Then 'process the child form – save, close, whatever frmActiveChild.txtDoc.Font = New Font(Me.Font, FontStyle.Bold) End If End If End Sub #Region "Menu Code" #Region "Window Code" Private Sub mnuCascade_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuCascade.Click Me.LayoutMdi(MdiLayout.Cascade) End Sub Private Sub mnuHorizontal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuHorizontal.Click Me.LayoutMdi(MdiLayout.TileHorizontal) End Sub Private Sub mnuVertical_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuVertical.Click Me.LayoutMdi(MdiLayout.TileVertical) End Sub #End Region #Region "File Code" Private Sub mnuNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuNew.Click NewFile() End Sub Private Sub mnuOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuOpen.Click End Sub Private Sub mnuSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuSave.Click End Sub Private Sub mnuSaveAs_Click(ByVal sender
-
I would appreciate it if some one could help me. I don't know how to write the code to save or save as in my forms. Here is the code that I have so far. Note that my parent form has file(new,open, save, save as, close) on it. I have already done the new code and I have been searching through the help files of .Net for 2 hours now with no help what so ever. Also please note that opion strict is set to on. Public Class frmMDI Inherits System.Windows.Forms.Form Dim counter As Integer = 1 Private Sub frmMDI_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Dim j As Integer 'For j = 1 To 3 ' Dim frmDocForm As New frmChild ' frmDocForm.MdiParent = Me ' frmDocForm.Show() 'Next End Sub Private Sub ToolBar1_ButtonClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolBarButtonClickEventArgs) Handles ToolBar1.ButtonClick If e.Button.Tag Is "new" Then NewFile() ElseIf e.Button.Tag Is "open" Then ElseIf e.Button.Tag Is "save" Then ElseIf e.Button.Tag Is "bold" Then Dim frmActiveChild As frmChild = Me.ActiveMdiChild If (Not frmActiveChild Is Nothing) Then 'process the child form – save, close, whatever frmActiveChild.txtDoc.Font = New Font(Me.Font, FontStyle.Bold) End If End If End Sub #Region "Menu Code" #Region "Window Code" Private Sub mnuCascade_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuCascade.Click Me.LayoutMdi(MdiLayout.Cascade) End Sub Private Sub mnuHorizontal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuHorizontal.Click Me.LayoutMdi(MdiLayout.TileHorizontal) End Sub Private Sub mnuVertical_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuVertical.Click Me.LayoutMdi(MdiLayout.TileVertical) End Sub #End Region #Region "File Code" Private Sub mnuNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuNew.Click NewFile() End Sub Private Sub mnuOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuOpen.Click End Sub Private Sub mnuSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuSave.Click End Sub Private Sub mnuSaveAs_Click(ByVal sender
if all you need is to write to a file, simply use the FileStream object in the frameworks (if it is then the title of your message is VERY misleading, if not, then my reply is useless :) ) the basics are to create a FileStream object reference
Dim MyFileStream as System.IO.FileStream
and then you need to create the file stream, by opening the file if it is a new file (there isn't a file with the same name at the same directory) you should create the file like so:MyFileStream = IO.File.Open(MyFilePath, IO.FileMode.CreateNew)
if the file already exists, you would probably want to erase the data and rewrite it do:FileStream = SystemIO.File.Open(MyFilePath, IO.FileMode.Truncate)
to check whether the file exists use:If System.IO.File.Exists(MyFilePath) Then ...
if you want to be really smart about it, you can scan the file to see what segements of have been chaged and only write those parts (mostly usefull in large files) Fade (Amit BS)