Results 1 to 4 of 4

Thread: [RESOLVED] RichTextBox Issues

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2016
    Location
    Sabattus, ME
    Posts
    87

    Resolved [RESOLVED] RichTextBox Issues

    Hi,
    I made a FontViewer program using WPF (See screen below)

    Here are the issues...
    1) When loading a saved RTF file, I am getting a bunch of font names appended at the end of my text that IS NOT VISIBLY IN THE RTF file
    2) After loading file into RTB, I can not longer change the font size

    Here is my saving and loading code for the RTF file.

    Code:
    'SAVE RTF
    If File.Exists(DemoRTFFile) Then
        fs = New FileStream(DemoRTFFile, FileMode.Open, FileAccess.Write)
            Using fs
                Dim RTBText As New TextRange(rtfEditor.Document.ContentStart, rtfEditor.Document.ContentEnd)
                RTBText.Save(fs, DataFormats.Rtf)
            End Using
    End If
    
    'Load RTF
    If File.Exists(DemoRTFFile) Then
        fs = New FileStream(DemoRTFFile, FileMode.Open, FileAccess.Read)
           Using fs
               Dim RTBText As New TextRange(rtfEditor.Document.ContentStart, rtfEditor.Document.ContentEnd)
               RTBText.Load(fs, DataFormats.Rtf)
            End Using
    End If
    Any insight would be appreciated

    Name:  fontviewerErr.jpg
Views: 1398
Size:  62.5 KB

  2. #2
    New Member
    Join Date
    May 2017
    Posts
    4

    Re: RichTextBox Issues

    I have the same problem. Please write did you find the solution? If yes, share it.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jul 2016
    Location
    Sabattus, ME
    Posts
    87

    Re: RichTextBox Issues

    Quote Originally Posted by comprar View Post
    I have the same problem. Please write did you find the solution? If yes, share it.
    Actually.... I finished the app but did not fix that problem because I decide I wasn't going to load an RTF.
    I commented out the loading code.

    Maybe this week sometimes I can figure out why it loads with those extra characters and let you know.
    Last edited by technipixel; May 25th, 2017 at 08:16 AM.

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Jul 2016
    Location
    Sabattus, ME
    Posts
    87

    Re: RichTextBox Issues

    I did another test with a new project and I got all those font names when I loaded the same old RTF file as above.

    But, when I created a new RTF file altogether I didn't get those font names at the end.

    So, I am assuming that something is weird about the RTF file I used a while back.

    Here is my updated load and save code....

    Code:
    Imports System.IO
    
    Class MainWindow
    
        Dim fs As FileStream
    
    
        Private Sub button1_Click(sender As Object, e As RoutedEventArgs) Handles button1.Click
            Dim dlg As New Microsoft.Win32.SaveFileDialog
            Dim filename As String = "myrftfile"
            dlg.InitialDirectory = Path.GetDirectoryName(filename)
            dlg.FileName = Path.GetFileName(filename)
            dlg.DefaultExt = ".rtf" ' Default file extension
            dlg.Filter = "RTF Files (.rtf)|*.rtf" ' Filter files by extension
    
            ' Show open file dialog box
            Dim result? As Boolean = dlg.ShowDialog()
    
            ' Process open file dialog box results
            If result = True Then
    
                ' Open document
                filename = dlg.FileName
    
                fs = New FileStream(filename, FileMode.Create, FileAccess.Write)
                Using fs
                    Dim RTBText As New TextRange(rtfEditor.Document.ContentStart, rtfEditor.Document.ContentEnd)
                    RTBText.Save(fs, DataFormats.Rtf)
                End Using
    
            End If
        End Sub
    
        Private Sub button_Click(sender As Object, e As RoutedEventArgs) Handles button.Click
            'Load RTB with text from RTF file
            'If File.Exists(DemoRTFFile) Then
            '    fs = New FileStream(DemoRTFFile, FileMode.Open, FileAccess.Read)
            '    Using fs
            '        ' Create a TextRange that comprises the start and end points of the RichTextBox text
            '        Dim RTBText As New TextRange(rtfEditor.Document.ContentStart, rtfEditor.Document.ContentEnd)
            '        RTBText.Load(fs, DataFormats.Rtf)
            '    End Using
            'End If
    
            Dim dlg As New Microsoft.Win32.OpenFileDialog
            Dim filename As String = "myrftfile"
            dlg.InitialDirectory = Path.GetDirectoryName(filename)
            dlg.FileName = Path.GetFileName(filename)
            dlg.DefaultExt = ".rtf" ' Default file extension
            dlg.Filter = "RTF Files (.rtf)|*.rtf" ' Filter files by extension
    
            ' Show open file dialog box
            Dim result? As Boolean = dlg.ShowDialog()
    
            ' Process open file dialog box results
            If result = True Then
    
                rtfEditor.Document.Blocks.Clear()
                rtfEditor.Focus()
    
                ' Open document
                filename = dlg.FileName
    
                fs = New FileStream(filename, FileMode.Open, FileAccess.Read)
                Using fs
                    Dim RTBText As New TextRange(rtfEditor.Document.ContentStart, rtfEditor.Document.ContentEnd)
                    RTBText.Load(fs, DataFormats.Rtf)
                End Using
    
            End If
        End Sub
    
        Private Sub button2_Click(sender As Object, e As RoutedEventArgs) Handles button2.Click
            'load default text 
            rtfEditor.AppendText("!" & Chr(34) & "#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’""•–—˜™š›œžŸ*¡¢£¤¥¦§¨©ª«¬*®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ")
        End Sub
    
    
    End Class

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