|
-
Jul 5th, 2004, 11:02 PM
#1
Thread Starter
Lively Member
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.
-
Jul 6th, 2004, 08:26 PM
#2
Thread Starter
Lively Member
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
-
Jul 6th, 2004, 09:32 PM
#3
Thread Starter
Lively Member
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?
-
Jul 7th, 2004, 03:05 AM
#4
yay gay
Just put
RichTextBox.Rtf = <that text> and you'll have it all working with the current formation settings the Rtf has
\m/  \m/
-
Jul 7th, 2004, 10:50 AM
#5
Thread Starter
Lively Member
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
-
Jul 7th, 2004, 01:07 PM
#6
Thread Starter
Lively Member
Anyone know if this is correct?
-
Jul 7th, 2004, 05:30 PM
#7
Sleep mode
Why don't you try and tell us if that is correct !!!
-
Jul 7th, 2004, 07:17 PM
#8
Thread Starter
Lively Member
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.
-
Jul 8th, 2004, 06:38 AM
#9
yay gay
I think there's a property called Lock or something like that that won't allow you to edit code
\m/  \m/
-
Nov 14th, 2004, 01:25 AM
#10
Addicted Member
Hi,
I tried the following code but it looks like text_stream Is Nothing.
VB Code:
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles MyBase.Load
Me.Text = Application.ProductName
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 + ".VersionHistory.txt")
If Not (text_stream Is Nothing) Then
Dim sr As New StreamReader(text_stream)
txtVersionHistory.Text = sr.ReadToEnd()
sr.Close()
End If
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|