Results 1 to 30 of 30

Thread: [RESOLVED] Saving extra information in a rtf file

Hybrid View

  1. #1
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429

    Re: Saving extra information in a rtf file

    The following will Save the contents of the Three RTB's. The Header, Main and Footer.

    Also, it can Load the pre-saved contents from an RTF (or .pwd) into the Three above mentioned RTB's:

    VB Code:
    1. Option Explicit On
    2. Option Strict On
    3.  
    4. Public Class Form1
    5.  
    6.     Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
    7.  
    8.         ' Add the Header RTB (emulating a Label) to the Hidden RTB maintaining formatting
    9.         Me.rtbHeader.SelectAll()
    10.         Me.rtbHeader.Copy()
    11.         Me.rtbHidden.DeselectAll()
    12.         Me.rtbHidden.Paste()
    13.  
    14.         Me.rtbHidden.AppendText(Environment.NewLine)
    15.  
    16.         ' Add the Main RTB to the Hidden RTB maintaining formatting
    17.         Me.rtbMain.SelectAll()
    18.         Me.rtbMain.Copy()
    19.         Me.rtbHidden.DeselectAll()
    20.         Me.rtbHidden.Paste()
    21.  
    22.         Me.rtbHidden.AppendText(Environment.NewLine)
    23.  
    24.         ' Add the Footer RTB (emulating a Label) to the Hidden RTB maintaining formatting
    25.         Me.rtbFooter.SelectAll()
    26.         Me.rtbFooter.Copy()
    27.         Me.rtbHidden.DeselectAll()
    28.         Me.rtbHidden.Paste()
    29.  
    30.         Dim sfd As New SaveFileDialog()
    31.         sfd.Title = "Please select where you want to save your file to"
    32.         sfd.Filter = "Rich Text Files (*.rtf)|*.rtf"
    33.         sfd.FilterIndex = 1
    34.         If sfd.ShowDialog = Windows.Forms.DialogResult.OK Then
    35.             rtbHidden.SaveFile(sfd.FileName)
    36.         End If
    37.         sfd.Dispose()
    38.  
    39.     End Sub
    40.  
    41.     Private Sub btnLoad_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLoad.Click
    42.  
    43.         ' Load the Hidden RTB for processing
    44.         Dim ofd As New OpenFileDialog()
    45.         ofd.Title = "Please select the file to open"
    46.         ofd.Filter = "Rich Text Files (*.rtf)|*.rtf"
    47.         ofd.FilterIndex = 1
    48.         If ofd.ShowDialog = Windows.Forms.DialogResult.OK Then
    49.             Me.rtbHidden.Clear()
    50.             Me.rtbHidden.LoadFile(ofd.FileName)
    51.         End If
    52.         ofd.Dispose()
    53.  
    54.         ' Extract the Header
    55.         Me.rtbHidden.Select(0, Me.rtbHidden.Text.IndexOf(vbLf))
    56.         Me.rtbHidden.Copy()
    57.         Me.rtbHeader.Clear()
    58.         Me.rtbHeader.Paste()
    59.  
    60.         ' Extract the Main
    61.         Me.rtbHidden.Select(Me.rtbHidden.Text.IndexOf(vbLf) + 1, Me.rtbHidden.Text.LastIndexOf(vbLf) - Me.rtbHidden.Text.IndexOf(vbLf))
    62.         Me.rtbHidden.Copy()
    63.         Me.rtbMain.Clear()
    64.         Me.rtbMain.Paste()
    65.  
    66.         ' Extract the Footer
    67.         Me.rtbHidden.Select(Me.rtbHidden.Text.LastIndexOf(vbLf) + 1, Me.rtbHidden.Text.Length - Me.rtbHidden.Text.IndexOf(vbLf) + 1)
    68.         Me.rtbHidden.Copy()
    69.         Me.rtbFooter.Clear()
    70.         Me.rtbFooter.Paste()
    71.  
    72.     End Sub
    73.  
    74. End Class

    Here is an image:
    Attached Images Attached Images  
    Last edited by Bruce Fox; Feb 19th, 2010 at 03:44 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width