473,395 Members | 2,079 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,395 software developers and data experts.

syntax highlighting revisited

I am looking at followin the suggestion made by Larry on my last post. (his
reply is on the bottom) it seems that you can't directly mess with the rich
text header text....specifically the addtion of the colortable (which
defines which colors can be used)

rtbCode.Rtf.Insert(10,"{\colortbl
;\red255\green0\blue0;\red0\green0\blue255;}")

does nothing.
neither does rewrting the entire header each time.... why is this? In order
for me to add color, i have to have a color table written at the beginning.
once again i turn to you all for help.

thanks, patrick
-------------------------------------------------------->
(Larrys post:
The RichTextBox offers a property called Rtf which gets/sets the actual
rich text as a String. If you look at this you will see stuff like
this:

this is normal text
\b this is bold
\i this is italic

I'm not sure what the exact syntax is, but basically this is how rich
text works - by inserting formatting instructions into the regular text
(like a primitive form of HTML if you like). You could try obtaining
the string from .Rtf, parsing it for 'ax', inserting the appropriate
formatting codes, then writing it back to .Rtf. This should avoid the
problems you get when you change the Selection.

To find out what the right control codes are, use WordPad to create a
..rtf file and examine that file using Notepad.
Nov 21 '05 #1
3 1517

Two issues here:

First, although 'Insert' might look like it 'does something', it is in
fact a function not a statement, so what you actually need to do is
something like

rtbCode.Rtf = rtbCode.Rtf.Insert( ... 'whatever

Second, a little playing around seems to suggest that the rich text box
only retains in the \colortbl those colours that are actually USED. So
if you just insert a \colortbl, but all your text is still the default
colour, the \colortbl won't be stored. But if you actual colour some
text with \cf1 ... \cf0, then colour 1 will be preserved. So what you
need to do in order to carry out your highlighting is this:

- Get the Rtf string
- If there's already a \colortbl, leave it, otherwise insert one
- Put the \cf colour tags around the text you want to highlight
- Write back the Rtf

Watch out for the Replace method of String; like Insert, it is a
function not a statement so you have to do stuff like

s = s.Replace("old", "new")

rather than the 'intuitive'

s.Replace("old", "new")

That one used to catch me in VB6 all the time.
Patrick Porter wrote:
I am looking at followin the suggestion made by Larry on my last post. (his reply is on the bottom) it seems that you can't directly mess with the rich text header text....specifically the addtion of the colortable (which defines which colors can be used)

rtbCode.Rtf.Insert(10,"{\colortbl
;\red255\green0\blue0;\red0\green0\blue255;}")

does nothing.
neither does rewrting the entire header each time.... why is this? In order for me to add color, i have to have a color table written at the beginning. once again i turn to you all for help.

thanks, patrick
-------------------------------------------------------->
(Larrys post:
The RichTextBox offers a property called Rtf which gets/sets the actual rich text as a String. If you look at this you will see stuff like
this:

this is normal text
\b this is bold
\i this is italic

I'm not sure what the exact syntax is, but basically this is how rich
text works - by inserting formatting instructions into the regular text (like a primitive form of HTML if you like). You could try obtaining
the string from .Rtf, parsing it for 'ax', inserting the appropriate
formatting codes, then writing it back to .Rtf. This should avoid the
problems you get when you change the Selection.

To find out what the right control codes are, use WordPad to create a
.rtf file and examine that file using Notepad.


Nov 21 '05 #2
thanks again. I still have the problem using both the replace and insert
functions.....it doesnt work.

Regex.Replace(code, "\\cf[01].* " & s, "\cf2" & s)

nothing even

rtbcode.rtf.replace("ax","bx") doesnt work.

i hate to keep bugging the group, but you have been so helpful.

thanks,

patrick

---> some of the code <----

code = rtbcode.rtf

For i = 0 To results.Length - 1

Dim d As Integer = match(i).Index

results(i) = match(i).Index

s = register.Item(x).ToString()

Regex.Replace(code, "\\cf[01].* " & s, "\cf2" & s)

rtbCode.Rtf = code

Dim str As String = rtbCode.Rtf

Next

------> end code <----

"Larry Lard" <la*******@hotmail.com> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...

Two issues here:

First, although 'Insert' might look like it 'does something', it is in
fact a function not a statement, so what you actually need to do is
something like

rtbCode.Rtf = rtbCode.Rtf.Insert( ... 'whatever

Second, a little playing around seems to suggest that the rich text box
only retains in the \colortbl those colours that are actually USED. So
if you just insert a \colortbl, but all your text is still the default
colour, the \colortbl won't be stored. But if you actual colour some
text with \cf1 ... \cf0, then colour 1 will be preserved. So what you
need to do in order to carry out your highlighting is this:

- Get the Rtf string
- If there's already a \colortbl, leave it, otherwise insert one
- Put the \cf colour tags around the text you want to highlight
- Write back the Rtf

Watch out for the Replace method of String; like Insert, it is a
function not a statement so you have to do stuff like

s = s.Replace("old", "new")

rather than the 'intuitive'

s.Replace("old", "new")

That one used to catch me in VB6 all the time.
Patrick Porter wrote:
I am looking at followin the suggestion made by Larry on my last

post. (his
reply is on the bottom) it seems that you can't directly mess with

the rich
text header text....specifically the addtion of the colortable (which

defines which colors can be used)

rtbCode.Rtf.Insert(10,"{\colortbl
;\red255\green0\blue0;\red0\green0\blue255;}")

does nothing.
neither does rewrting the entire header each time.... why is this? In

order
for me to add color, i have to have a color table written at the

beginning.
once again i turn to you all for help.

thanks, patrick
-------------------------------------------------------->
(Larrys post:
The RichTextBox offers a property called Rtf which gets/sets the

actual
rich text as a String. If you look at this you will see stuff like
this:

this is normal text
\b this is bold
\i this is italic

I'm not sure what the exact syntax is, but basically this is how rich
text works - by inserting formatting instructions into the regular

text
(like a primitive form of HTML if you like). You could try obtaining
the string from .Rtf, parsing it for 'ax', inserting the appropriate
formatting codes, then writing it back to .Rtf. This should avoid the
problems you get when you change the Selection.

To find out what the right control codes are, use WordPad to create a
.rtf file and examine that file using Notepad.

Nov 21 '05 #3

Methods called Replace are *functions* that *return* values. They don't
*change* their input values. After the line of code

rtbcode.rtf.replace("ax","bx")

rtbcode.rtf will be exactly the same as it was before, since you have
done nothing with the return value from the function. VB.NET is perhaps
slightly remiss in not warning you that you are doing this; although it
might get annoying to get warned every time a function return value is
discarded.

Anyway, if you want to change the value of a string you must assign the
new value to it: so not

Regex.Replace(code, "\\cf[01].* " & s, "\cf2" & s)

but rather

code = Regex.Replace(code, "\\cf[01].* " & s, "\cf2" & s)

and so on.

Patrick Porter wrote:
thanks again. I still have the problem using both the replace and insert functions.....it doesnt work.

Regex.Replace(code, "\\cf[01].* " & s, "\cf2" & s)

nothing even

rtbcode.rtf.replace("ax","bx") doesnt work.

i hate to keep bugging the group, but you have been so helpful.

thanks,

patrick

---> some of the code <----

code = rtbcode.rtf

For i = 0 To results.Length - 1

Dim d As Integer = match(i).Index

results(i) = match(i).Index

s = register.Item(x).ToString()

Regex.Replace(code, "\\cf[01].* " & s, "\cf2" & s)

rtbCode.Rtf = code

Dim str As String = rtbCode.Rtf

Next

------> end code <----

"Larry Lard" <la*******@hotmail.com> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...

Two issues here:

First, although 'Insert' might look like it 'does something', it is in fact a function not a statement, so what you actually need to do is
something like

rtbCode.Rtf = rtbCode.Rtf.Insert( ... 'whatever

Second, a little playing around seems to suggest that the rich text box only retains in the \colortbl those colours that are actually USED. So if you just insert a \colortbl, but all your text is still the default colour, the \colortbl won't be stored. But if you actual colour some text with \cf1 ... \cf0, then colour 1 will be preserved. So what you need to do in order to carry out your highlighting is this:

- Get the Rtf string
- If there's already a \colortbl, leave it, otherwise insert one
- Put the \cf colour tags around the text you want to highlight
- Write back the Rtf

Watch out for the Replace method of String; like Insert, it is a
function not a statement so you have to do stuff like

s = s.Replace("old", "new")

rather than the 'intuitive'

s.Replace("old", "new")

That one used to catch me in VB6 all the time.
Patrick Porter wrote:
I am looking at followin the suggestion made by Larry on my last

post. (his
reply is on the bottom) it seems that you can't directly mess with

the rich
text header text....specifically the addtion of the colortable (which
defines which colors can be used)

rtbCode.Rtf.Insert(10,"{\colortbl
;\red255\green0\blue0;\red0\green0\blue255;}")

does nothing.
neither does rewrting the entire header each time.... why is this?
In order
for me to add color, i have to have a color table written at the

beginning.
once again i turn to you all for help.

thanks, patrick
-------------------------------------------------------->
(Larrys post:
The RichTextBox offers a property called Rtf which gets/sets the

actual
rich text as a String. If you look at this you will see stuff like
this:

this is normal text
\b this is bold
\i this is italic

I'm not sure what the exact syntax is, but basically this is how

rich text works - by inserting formatting instructions into the regular

text
(like a primitive form of HTML if you like). You could try obtaining the string from .Rtf, parsing it for 'ax', inserting the appropriate formatting codes, then writing it back to .Rtf. This should avoid the problems you get when you change the Selection.

To find out what the right control codes are, use WordPad to create a .rtf file and examine that file using Notepad.


Nov 21 '05 #4

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

Similar topics

9
by: Jay Davis | last post by:
I use xemacs and syntax highlighting for my IDE, but I'm not a big fan of the default syntax highlighting colors. For instance, in 'def fun():' both 'def' and 'fun' are the same color. I kind of...
9
by: news.microsoft.com | last post by:
Dear all, I have to do a source code editor to implement syntax hilighted with special colors , IntelliSense function. Could anybody give me some tips or links? Thanks,
4
by: Bob hotmail.com> | last post by:
Everyone I have been spending weeks looking on the web for a good tutorial on how to use regular expressions and other methods to satisfy my craving for learning how to do FAST c-style syntax...
4
by: Patrick Porter | last post by:
Arrrgh! I have tried everything (ok, not EVERYTHING) but i cant get solve the problem of getting syntax highlighting in a rich textbox. in the code below, im attempting to highlight all of the...
4
by: frikker | last post by:
Hello, I have an idea for a project which involves an editor that supports syntax highlighting. This would be for any language, particularly php, html, css, etc. I would like to write this...
2
by: rockstar_ | last post by:
Hello all- I'm developing a Content Management software for my own site, and possibly package and deploy to other sites (for friends, family, etc.) The content management software is combined...
11
by: Christoph Burschka | last post by:
Are there any free PHP libraries/utility functions that can color the syntax of various programming languages (eg. Java and C++)? I am posting code snippets on my site and would like to know if...
0
by: Scott | last post by:
Hi, I think I may have finally found a IDE/text editor that I like, but, it still haves one problem. Geany haves syntax highlighting, but it is not very good for Python. It only seems to have...
2
by: PJ6 | last post by:
Years ago I looked for a text editor control that would do automatic keyword highlighting, to no avail. I found sample code to roll my own, but all of that was crap (mostly because of the way the...
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:
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...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.