473,394 Members | 1,935 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Can't change RichTextBox Color Table.

I'm trying to change the color table of a RichTextBox. When the app starts,
it has the following RTF:
{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl {\f0\fnil\fcharset0
A2like;}}
{\colortbl ;\red255\green255\blue0;}
\viewkind4\uc1\pard\fi-375\li375\cf1\f0\fs24\par
}

Calling the following code to alter the color table from Form1.Load:

Public Sub AddColorTable()
Dim x As String = txtChat.Rtf
Dim y As String = ""
Dim z As String = ""
Dim sr As New StringReader(x)
While sr.Peek 0
z = sr.ReadLine
If z.ToLower.StartsWith("{\colortbl") Then
z = z.Replace(";}", RTFColors & "}")
End If
y &= z & vbCrLf
End While
sr.Close()
txtChat.Rtf = y
End Sub

Has no effect.

The routine works fine. Checking the 'y' variable just before assigning it
to txtChat.Rtf shows that it is correctly modified.

{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl {\f0\fnil\fcharset0
A2like;}}
{\colortbl
;\red255\green255\blue0;\red255\green255\blue255;\ red0\green0\blue0;\red255\green0\blue0;\red255\gre en128\blue0;\red255\green255\blue0;\red128\green25 5\blue0;\red0\green255\blue0;\red0\green255\blue12 8;\red0\green255\blue255;\red0\green128\blue255;\r ed0\green0\blue255;\red128\green0\blue255;\red255\ green0\blue255;\red255\green0\blue128;\red192\gree n192\blue192;\red64\green64\blue64;\red128\green0\ blue0;\red128\green64\blue0;\red128\green128\blue0 ;\red64\green128\blue0\red0\green128\blue0;\red0\g reen128\blue64;\red0\green128\blue128;\red0\green6 4\blue128;\red0\green0\blue128;\red64\green0\blue1 28;\red128\green0\blue128;\red128\green0\blue64;}
\viewkind4\uc1\pard\fi-375\li375\f0\fs24\par
}

Can anyone help?
Dec 17 '06 #1
1 2681
Terry Olsen wrote:
I'm trying to change the color table of a RichTextBox.
Calling the following code to alter the color table from Form1.Load:
Public Sub AddColorTable()
Dim x As String = txtChat.Rtf
Dim y As String = ""
Dim z As String = ""
Dim sr As New StringReader(x)
While sr.Peek 0
z = sr.ReadLine
If z.ToLower.StartsWith("{\colortbl") Then
z = z.Replace(";}", RTFColors & "}")
End If
y &= z & vbCrLf
End While
sr.Close()
txtChat.Rtf = y
End Sub
There's no guarantee that the colortbl entry starts on a new line;
indeed, I'd be surprised if it did.
You might be better off loading the whole RTF "string" in one go, then
replace the bit you're after, something like

Imports System.Text.RegularExpressions

Dim sr as New StringReader(x)
y = sr.ReadToEnd()
sr.Close()

y = Regex.Replace( y, "{\\colortbl.*}" _
, "{\colortbl " & RTFColors & ";}" )

txtChat.Rtf = y

HTH,
Phill W.
Dec 18 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: JMe9ka | last post by:
I'm looking to export data from my application into a document. The data represented needs to be shown in a table (like a table within a Word document). I am currently using Word automation to...
2
by: Reinhard Vornholt | last post by:
Hi, I have problems with the Windows.Forms.RichtextBox Control of the VS. I have a text that is written with WordPad. In this text there are tables. The cells in the tables are holding multiple...
4
by: Du | last post by:
I want to format the text within my richtextbox. However I have large amount of text to change, simply using richtextbox.select and format is not pratical. How do I change text format using...
10
by: D Steward | last post by:
I can't seem to add a newline (/n) to get a richtextbox control to display text on successive lines. The text that I type is overwritten. How do I remedy this My example richTextBox->Multiline...
5
by: Daniel | last post by:
Hi all, How to make use of richtextbox class by typing imports system.windows.forms to create a runtime richtextbox and allow user to copy and paste data? Any ideas? guidelineS? thank you in...
2
by: **Developer** | last post by:
Did the RichTextBox control change in VS2005?
0
by: landon.chelf | last post by:
I'm working with a RichTextBox control and am loading the following rtf into it. {\rtf1\ansi\deff0 {\fonttbl {\f0\fswiss Arial;} } \deflang1033\plain\fs20 {\pard...
0
Ajm113
by: Ajm113 | last post by:
Contributing To: Saving RichTextBox from Tab Control Ok, I have a question what would I use if I wanted to do something like a paste function in a Rich Text Box using the code on that thread?...
1
by: Andrus | last post by:
I need to save font selected by user by Ctrl+MouseWheel in Winforms RichTextBox. I tried override below but this does not remember font: in this method Font.Size property seems to be always...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.