[RESOLVED] RichTextBox Issues-VBForums
Results 1 to 4 of 4

Thread: [RESOLVED] RichTextBox Issues

  1. #1

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

    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: 581
Size:  62.5 KB
    My Sites: TechniPixel Solutions Pixelink Media
    Windows 7 10G RAM NIV-GForce GT 640 Graphics Card Visual Studio 2015
    Software Code: VB6, VBA, .NET (C# & VB), Lazarus (Free Pascal), InnoSetup
    Other: sql, php, html, CSS, javascript, actionscript

  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
    65

    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 09:16 AM.
    My Sites: TechniPixel Solutions Pixelink Media
    Windows 7 10G RAM NIV-GForce GT 640 Graphics Card Visual Studio 2015
    Software Code: VB6, VBA, .NET (C# & VB), Lazarus (Free Pascal), InnoSetup
    Other: sql, php, html, CSS, javascript, actionscript

  4. #4

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

    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
    My Sites: TechniPixel Solutions Pixelink Media
    Windows 7 10G RAM NIV-GForce GT 640 Graphics Card Visual Studio 2015
    Software Code: VB6, VBA, .NET (C# & VB), Lazarus (Free Pascal), InnoSetup
    Other: sql, php, html, CSS, javascript, actionscript

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.