how to maintain the color of a text in a richtextbox when inside of two " " and " "

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
hi , I am just creating a simple editor and I have an event in the richtextbox that everything that is inside the " " will be colored as red. I have the code below. there is a problem , when a text in the middle of two "" , it is also colored as red
even it is not inside the ""..
for example :
"hello"
good
"world"
the word hello and world are in red , and the word good is also red
pleas help me .
thank you in advance

<span style="font-family:Segoe UI,Lucida Grande,Verdana,Arial,Helvetica,sans-serif; font-size:13px; line-height:16px
<pre style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; list-style-type:none; text-decoration:none; word-wrap:break-word; text-align:left; padding:0px; margin:0px; border:0px none initial <span style="color:#0000ff <br/>[/code]
<pre style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; list-style-type:none; text-decoration:none; word-wrap:break-word; text-align:left; padding:0px; margin:0px; border:0px none initial <span style="color:#0000ff <div style="color:Black;background-color:White; <pre>
<span style="color:Blue; Imports System.Text.RegularExpressions

<span style="color:Blue; Public <span style="color:Blue; Class Form1
<span style="color:Green; You Must Have A Richtextbox Named RichTextBox1
<span style="color:Green;

<span style="color:Blue; Private <span style="color:Blue; Sub RichTextBox1_TextChanged(<span style="color:Blue; ByVal sender <span style="color:Blue; As <span style="color:Blue; Object, <span style="color:Blue; ByVal e <span style="color:Blue; As System.EventArgs) <span style="color:Blue; Handles RichTextBox1.TextChanged

<span style="color:Blue; Dim MyRegex <span style="color:Blue; As <span style="color:Blue; New Regex(<span style="color:#A31515; "((b)?((x22)(?s:(.+))?(x22))(b)?)")

<span style="color:Blue; Dim MC <span style="color:Blue; As MatchCollection = MyRegex.Matches(RichTextBox1.Text)

<span style="color:Blue; Dim OldSel <span style="color:Blue; As <span style="color:Blue; Integer = RichTextBox1.SelectionStart <span style="color:Green; Old Selection Start

<span style="color:Green; We Must Restor Everything To Black Before Coloring
<span style="color:Green;
RichTextBox1.SelectAll()
RichTextBox1.SelectionColor = Color.Black
RichTextBox1.DeselectAll()

<span style="color:Blue; For <span style="color:Blue; Each M <span style="color:Blue; As Match <span style="color:Blue; In MC
RichTextBox1.SelectionStart = M.Index
RichTextBox1.SelectionLength = M.Value.Length
RichTextBox1.SelectionColor = Color.Red <span style="color:Green; The Color That You Want
RichTextBox1.DeselectAll()
<span style="color:Blue; Next

RichTextBox1.SelectionStart = OldSel <span style="color:Green; Restore Old Selection
<span style="color:Blue; End <span style="color:Blue; Sub

<span style="color:Blue; End <span style="color:Blue; Class
[/code]
<br/><br/>[/code]


View the full article
 
Back
Top