Results 1 to 10 of 10

Thread: Embedded RTF [Gave up on]

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2003
    Posts
    127

    Angry Embedded RTF [Gave up on]

    I have the Help.rtf set as Embedded Resource and am trying to use this to read the Help.rtf file into the Rich Text Box and it doesn't load anything. Can someone give me pointers on what part of it's wrong.... or maybe a better way of doing it.

    P.S. My Help.rtf file contains text, links to websites and graphics if this makes a diffrence.

    Code:
    Imports System.IO
    Public Class Form3
        Inherits System.Windows.Forms.Form
    
    +windows Form Designer Generated Code
    
     Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
            Dim stream As Stream = Me.GetType().Assembly.GetManifestResourceStream("MyNameSpace.Help.rtf")
            If Not (stream Is Nothing) Then
                Dim sr As New StreamReader(stream)
                RichTextBox1.LoadFile(stream, RichTextBoxStreamType.RichText)
                sr.Close()
            End If
        End Sub
    End Class
    Last edited by teamdad; Aug 3rd, 2004 at 01:07 PM.

  2. #2

    Thread Starter
    Lively Member
    Join Date
    Dec 2003
    Posts
    127
    Figured it out.... i'm so proud of myself. lol I took a diffrent approach and it works brilliently. Done correctly this allows you to create a nice text, html link and graphics type of look that can be loaded into a Rich Text Box that is set on a form either in fixed size or Dock/Fill and it's resizable with the form.

    I caught on to the idea when browsing the Web for creative ways to make an About box that looks better than what I could come up with all the lables and picture boxes and the like.

    Code:
    Imports System.IO
    Public Class Form3
        Inherits System.Windows.Forms.Form
    
    +windows Form Designer Generated Code
    
    Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
            Dim executing_assembly As System.Reflection.Assembly = _
        Me.GetType.Assembly.GetEntryAssembly()
    
            Dim my_namespace As String = executing_assembly.GetName().Name.ToString()
    
            Dim text_stream As Stream = executing_assembly.GetManifestResourceStream(my_namespace + ".Help.rtf")
            If Not (text_stream Is Nothing) Then
                Dim stream_reader As New StreamReader(text_stream)
                RichTextBox1.Text = stream_reader.ReadToEnd()
                stream_reader.Close()
            End If
    
        End Sub

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Dec 2003
    Posts
    127
    Well.... I thought it was resolved. It works great for plain text but when you try changing text color or add a graphic to the file your save as an RTF and then embedd it the thing goes nuts. It creates the funky headers or code of the program that defines the color change or makes up the graphic.

    Here's an example:

    {\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fswiss\fcharset0 Arial;}}
    {\colortbl ;\red255\green0\blue0;\red0\green0\blue255;}
    {\*\generator Msftedit 5.41.15.1503;}\viewkind4\uc1\pard\f0\fs20 ATTENTION: This License Agreement is a legal agreement between you (either an individual or a single entity) and John Doe (hereafter called the "creator"). It defines what you may do with the product and contains limitations on warranties and/or remedies. This license is granted by the creator when purchased either directly or though any authorized agent. \par
    \par

    Anyone have ideas on what's happening or how to fix it?

  4. #4
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    Just put

    RichTextBox.Rtf = <that text> and you'll have it all working with the current formation settings the Rtf has
    \m/\m/

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Dec 2003
    Posts
    127
    Thanks PT Exorcist,

    Would I add this like I hilighted in RED below? and from what I understand, you are saying this will correctly show the RTF file as I have created it... with colored text and any pictures I place in it? Thanks in advance for the assist on this.

    Code:
    Imports System.IO
    Public Class Form3
        Inherits System.Windows.Forms.Form
    
    +windows Form Designer Generated Code
    
    Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
            Dim executing_assembly As System.Reflection.Assembly = _
        Me.GetType.Assembly.GetEntryAssembly()
    
            Dim my_namespace As String = executing_assembly.GetName().Name.ToString()
    
            Dim text_stream As Stream = executing_assembly.GetManifestResourceStream(my_namespace + ".Help.rtf")
            If Not (text_stream Is Nothing) Then
                Dim stream_reader As New StreamReader(text_stream)
                RichTextBox.Rtf =  stream_reader.ReadToEnd()
                stream_reader.Close()
            End If
    
        End Sub

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Dec 2003
    Posts
    127
    Anyone know if this is correct?

  7. #7
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Why don't you try and tell us if that is correct !!!

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Dec 2003
    Posts
    127
    Well, I was at work when I posted before so I didn't have access to test it. I was just trying to clarify if that was the location indicated so I could test it when I got home.

    It does the job of displaying the colored text and the pictures but if you click on the picture it hilights it and will let you edit it's size in the RichTextBox as if it was in design mode or something. It also does this to the links Google test <http://www.google.com>
    instead of just showing the anchor like it would with HTML.

    I tried using this to disable access/editing the RichTextBox but then it turns the background grey, it won't scroll and the links are still doing the same thing.

    Code:
    RichTextBox1.Enabled = False
    Last edited by teamdad; Jul 7th, 2004 at 10:16 PM.

  9. #9
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    I think there's a property called Lock or something like that that won't allow you to edit code
    \m/\m/

  10. #10
    Addicted Member
    Join Date
    Apr 2003
    Location
    Australia
    Posts
    252
    Hi,

    I tried the following code but it looks like text_stream Is Nothing.

    VB Code:
    1. Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _
    2.     Handles MyBase.Load
    3.  
    4.         Me.Text = Application.ProductName
    5.  
    6.         Dim executing_assembly As System.Reflection.Assembly = _
    7.         Me.GetType.Assembly.GetEntryAssembly()
    8.  
    9.         Dim my_namespace As String = executing_assembly.GetName().Name.ToString()
    10.         Dim text_stream As Stream = _
    11.         executing_assembly.GetManifestResourceStream(my_namespace + ".VersionHistory.txt")
    12.  
    13.         If Not (text_stream Is Nothing) Then
    14.             Dim sr As New StreamReader(text_stream)
    15.             txtVersionHistory.Text = sr.ReadToEnd()
    16.             sr.Close()
    17.         End If
    18.  
    19.     End Sub

    Much appreciated your help.

    Cheers,
    McoreD

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