Click here to Skip to main content
15,907,913 members
Home / Discussions / C#
   

C#

 
QuestionLatebinding? Pin
T_Armstrong14-Nov-06 18:08
T_Armstrong14-Nov-06 18:08 
AnswerRe: Latebinding? Pin
Christian Graus14-Nov-06 19:51
protectorChristian Graus14-Nov-06 19:51 
AnswerRe: Latebinding? Pin
Nicholas Butler14-Nov-06 21:18
sitebuilderNicholas Butler14-Nov-06 21:18 
QuestionNeed to find some required text in RichtextBox Pin
M Riaz Bashir14-Nov-06 18:04
M Riaz Bashir14-Nov-06 18:04 
AnswerRe: Need to find some required text in RichtextBox Pin
saqib8214-Nov-06 19:41
saqib8214-Nov-06 19:41 
QuestionClipboard help Pin
Jon Stroh14-Nov-06 17:06
Jon Stroh14-Nov-06 17:06 
AnswerRe: Clipboard help Pin
saqib8214-Nov-06 19:40
saqib8214-Nov-06 19:40 
Questionhow to highlight syntax as soon as loading text file in to richtextbox Pin
veluru krishna14-Nov-06 16:56
veluru krishna14-Nov-06 16:56 
hi all,
I am able to highlight the syntax when I type the text ie c# code in richtextbox using the following code

code:

// Calculate the starting position of the current line.
int start = 0, end = 0;
for (start = richTextBox1.SelectionStart - 1; start > 0; start--)
{
if (richTextBox1.Text[start] == '\n')
{
start++;
break;
}
}

// Calculate the end position of the current line.
for (end = richTextBox1.SelectionStart; end < richTextBox1.Text.Length; end++)
{
if (richTextBox1.Text[end] == '\n')
break;
}

// Extract the current line that is being edited.
String line = richTextBox1.Text.Substring(start, end - start);

// Backup the users current selection point.
int selectionStart = richTextBox1.SelectionStart;
int selectionLength = richTextBox1.SelectionLength;

// Split the line into tokens.
Regex r = new Regex("([ \\t{}();])");
string [] tokens = r.Split(line);
int index = start;
foreach (string token in tokens) {
// Set the token's default color and font.
richTextBox1.SelectionStart = index;
richTextBox1.SelectionLength = token.Length;
richTextBox1.SelectionColor = Color.Black;
richTextBox1.SelectionFont = new Font("Courier New", 10, FontStyle.Regular);

// Check whether the token is a keyword.
String [] keywords = {"abstract","base","bool","break","byte","case","catch",,...."using","virtual","void" };
for (int i = 0; i < keywords.Length; i++)
{
if (keywords[i] == token)
{
// Apply alternative color and font to highlight keyword.
richTextBox1.SelectionColor = Color.Blue;
richTextBox1.SelectionFont = new Font("Courier New", 10, FontStyle.Bold);
break;
}
}
index += token.Length;
}
// Restore the users current selection point.
richTextBox1.SelectionStart = selectionStart;
richTextBox1.SelectionLength = selectionLength;

But my aim is to write c# code in text file and load that text file into a richtextbox and as soon as i load the text file into richtextbox the syntax should be highlighted.but in my case i am not getting that.

can anyone help me to solve this problem


Don't wait to hear a word of thanks from anybody when you help them instead ask them to help three other people and ask them to continue in chain.

QuestionACPI and WMI in C# Pin
Robert Jacob14-Nov-06 12:04
Robert Jacob14-Nov-06 12:04 
QuestionAutoclick type pgm Pin
Zinc Oianoid14-Nov-06 11:57
Zinc Oianoid14-Nov-06 11:57 
AnswerRe: Autoclick type pgm Pin
Christian Graus14-Nov-06 20:12
protectorChristian Graus14-Nov-06 20:12 
GeneralRe: Autoclick type pgm Pin
Zinc Oianoid16-Nov-06 5:03
Zinc Oianoid16-Nov-06 5:03 
QuestionDisplay as string in datetime custom format Pin
Mary Parkhouse14-Nov-06 11:14
Mary Parkhouse14-Nov-06 11:14 
AnswerRe: Display as string in datetime custom format Pin
Guffa14-Nov-06 12:27
Guffa14-Nov-06 12:27 
GeneralRe: Display as string in datetime custom format Pin
Christian Graus14-Nov-06 12:30
protectorChristian Graus14-Nov-06 12:30 
GeneralRe: Display as string in datetime custom format Pin
Mary Parkhouse15-Nov-06 6:16
Mary Parkhouse15-Nov-06 6:16 
AnswerRe: Display as string in datetime custom format Pin
Christian Graus14-Nov-06 12:30
protectorChristian Graus14-Nov-06 12:30 
QuestionPassing variables from C# to JavaScript Pin
DanB198314-Nov-06 10:53
DanB198314-Nov-06 10:53 
AnswerRe: Passing variables from C# to JavaScript Pin
Christian Graus14-Nov-06 12:32
protectorChristian Graus14-Nov-06 12:32 
AnswerRe: Passing variables from C# to JavaScript Pin
Guffa14-Nov-06 12:34
Guffa14-Nov-06 12:34 
GeneralRe: Passing variables from C# to JavaScript Pin
DanB198314-Nov-06 22:03
DanB198314-Nov-06 22:03 
AnswerRe: Passing variables from C# to JavaScript Pin
Justin.Jones16-Nov-06 9:06
Justin.Jones16-Nov-06 9:06 
QuestionScreen Saver status Pin
Daithi Brennan14-Nov-06 7:45
Daithi Brennan14-Nov-06 7:45 
AnswerRe: Screen Saver status Pin
Luc Pattyn14-Nov-06 12:55
sitebuilderLuc Pattyn14-Nov-06 12:55 
Questionhow to use Sql Server 2005 Reporting Services ? Pin
hdv21214-Nov-06 7:37
hdv21214-Nov-06 7:37 

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.