Hello, I have a code thats changes colors for special words and sets brackets for sql query.
But I have problem whan I press button it's makes all text blue.
I type a same code in richtextbox like this: "select aaa from bbb where a=1 or a=2 or a=3 and b=2 or b=3 and c=2 or c=3". It's make words colored like 'select, from, where, and, or to' color blue.
Can someone tell me why it's color all text blue after I press button and program adds brackets ?
Here is my code:
http://paste.php.lv/7cd1b3da1717783542b2a414d73a1e30?lang=csharp
Loading
FroglegPosted Feb 21, 2011, 8:06 AM
HighlightPhrase(richTextBox1,richTextBox1.Text,Color.Black);
and then called the method to color the text again
Janis PeksaPosted Feb 21, 2011, 8:13 AM
Janis PeksaPosted Feb 21, 2011, 7:59 AM
I don't know how to change all text to black.
And send send my method again.
I tried like this: richTextbox1.ForeColor = Color.Black;
But nothing happends.
Maybe you know how to change all text to black ?
FroglegPosted Feb 21, 2011, 7:57 AM
Without knowing the full string I'm only guessing
Janis PeksaPosted Feb 21, 2011, 7:24 AM
Did you try my code and see the problem ?
FroglegPosted Feb 21, 2011, 7:11 AM
Janis PeksaPosted Feb 21, 2011, 7:02 AM
It's works 50/50. Selects word and color it and stay selected, I don't need it to be selected.
Try my code and you will see what I need.
And you will see what problem I have.
FroglegPosted Feb 21, 2011, 6:58 AM
put
highLightTextBlue("Select");
highLightTextBlue("where");
highLightTextBlue(" or");
in richTextBox1_TextChanged event
once you type last letter it should change text color as required
Janis PeksaPosted Feb 21, 2011, 6:51 AM
And I need on TextChange event not on click event.
My code works fine with text color change.
But whan I press button it's adds brackets
where needed but makes all text blue why ? :(
Maybe someone can show me how to make it right ?
FroglegPosted Feb 21, 2011, 6:45 AM
private void button1_Click(object sender, EventArgs e)
{
highLightTextBlue("Select");
highLightTextBlue("where");
highLightTextBlue(" or");
}
public void highLightTextBlue(string wh)
{
int stIndex = 0;
stIndex = richTextBox1.Find(wh, stIndex, RichTextBoxFinds.MatchCase);
while (stIndex != -1)
{
if (richTextBox1.SelectedText == wh )
{
richTextBox1.SelectionLength = wh.Length;
richTextBox1.SelectionColor = Color.Blue;
}
stIndex = richTextBox1.Find(wh, stIndex + 1, RichTextBoxFinds.MatchCase);
}
}
Note = only blue text changed - you will have to create a method for other colors