Click here to Skip to main content
15,914,014 members
Home / Discussions / C#
   

C#

 
AnswerRe: hai can u help me out Pin
mav.northwind10-May-07 10:09
mav.northwind10-May-07 10:09 
GeneralRe: hai can u help me out Pin
siddabattini10-May-07 19:53
siddabattini10-May-07 19:53 
QuestionForms Pin
Alireza38399-May-07 18:42
Alireza38399-May-07 18:42 
AnswerRe: Forms Pin
Christian Graus9-May-07 18:59
protectorChristian Graus9-May-07 18:59 
GeneralRe: Forms Pin
Alireza38399-May-07 19:14
Alireza38399-May-07 19:14 
GeneralRe: Forms Pin
Christian Graus9-May-07 19:59
protectorChristian Graus9-May-07 19:59 
QuestionGetting values from a Datagrid Pin
Michael1019-May-07 16:07
Michael1019-May-07 16:07 
QuestionRTF/Regex Question Pin
Mike Hankey9-May-07 15:59
mveMike Hankey9-May-07 15:59 
Hello,

I'm trying to highlight selected text in a RichTextBox Control.
I want to do this by using the RTF control code \cbn where n = index.
As I understand you prefix the selected text with a \cbn code to change the background color to the highlight color then Postfix it with another \cbn code to reset color back.
See COMMENT BELOW for full description


//RTF Color codes with indices into Color Table
private const string clrDefault = @"\cf1 ";
private const string clrKeyword = @"\cf2 ";
private const string clrLiteral = @"\cf3 ";
private const string clrOutlining = @"\cf4 ";
private const string clrComment = @"\cf5 ";
private const string clrSelect = @"\cf6 ";

//The actual individual entries in the Coor Table
protected static string colorDefault = @"\red0\green0\blue0;";
protected static string colorKeyword = @"\red15\green0\blue255;";
protected static string colorLiteral = @"\red200\green105\blue36;";
protected static string colorOutlining = @"\red27\green175\blue78;";
protected static string colorComment = @"\red160\green160\blue160;";
protected static string colorSelect = @"\red90\green90\blue90;";

//Code to build the Color Table string
protected static string rtfColorTable = @"{\colortbl ;" +
colorDefault +
colorKeyword +
colorLiteral +
colorOutlining +
colorComment +
colorSelect +
@"}";

public static void HighlightSelection(RichTextBox rtb, string selTxt)
{
string result = rtb.Rtf;

//Replaces existing colorTable with mine
result = CreateColorTable(result);

Regex r = new Regex(selTxt);

// COMMENT BELOW
//If I use clrSelect + selText + clrDefault
// i.e. @"\cf6 " + selText + @"\cf1 "
//The proper keywords foreColor changes to gray.
//But when I use the \cbn equiv. it doesn't??

result = r.Replace(
result,
@"\cb6 " + selTxt + @"\cb1 ");

rtb.Rtf = result;
}

Thanks for your time!
Mike

P.S. Does anyone know a good Regex reference?


Light travels faster than sound. That's why some people appear right until you hear them speak.

AnswerRe: RTF/Regex Question Pin
subrata.jana9-May-07 20:38
subrata.jana9-May-07 20:38 
GeneralRe: RTF/Regex Question Pin
Mike Hankey10-May-07 1:26
mveMike Hankey10-May-07 1:26 
Questionhelp...how to highlight buttons in c#? Pin
Missy Glory9-May-07 15:26
Missy Glory9-May-07 15:26 
AnswerRe: help...how to highlight buttons in c#? Pin
Vikram A Punathambekar9-May-07 18:01
Vikram A Punathambekar9-May-07 18:01 
AnswerRe: help...how to highlight buttons in c#? Pin
marky7779-May-07 21:00
marky7779-May-07 21:00 
AnswerRe: help...how to highlight buttons in c#? Pin
Leyu10-May-07 2:21
Leyu10-May-07 2:21 
QuestionSimple hashcode [modified] Pin
gumi_r@msn.com9-May-07 13:04
gumi_r@msn.com9-May-07 13:04 
AnswerRe: Simple hashcode Pin
Luc Pattyn9-May-07 14:20
sitebuilderLuc Pattyn9-May-07 14:20 
GeneralRe: Simple hashcode [modified] Pin
gumi_r@msn.com9-May-07 22:33
gumi_r@msn.com9-May-07 22:33 
GeneralRe: Simple hashcode Pin
Luc Pattyn9-May-07 22:48
sitebuilderLuc Pattyn9-May-07 22:48 
GeneralRe: Simple hashcode [modified] Pin
gumi_r@msn.com9-May-07 23:02
gumi_r@msn.com9-May-07 23:02 
GeneralRe: Simple hashcode Pin
Luc Pattyn9-May-07 23:09
sitebuilderLuc Pattyn9-May-07 23:09 
QuestionRegular Expression for Getting file urls. Pin
Neo_Shehpar9-May-07 12:23
Neo_Shehpar9-May-07 12:23 
AnswerRe: Regular Expression for Getting file urls. Pin
Ed.Poore9-May-07 12:41
Ed.Poore9-May-07 12:41 
AnswerRe: Regular Expression for Getting file urls. Pin
zinc_z10-May-07 1:31
zinc_z10-May-07 1:31 
QuestionSharing an object in Assembly ? Pin
zinc_z9-May-07 11:59
zinc_z9-May-07 11:59 
AnswerRe: Sharing an object in Assembly ? Pin
Judah Gabriel Himango9-May-07 12:34
sponsorJudah Gabriel Himango9-May-07 12:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.