-1
I need to create a winform to change the color of expressions that start with '@'.
For example:
nothing @expresso nada
The @expression needs to be another color.
The text will come from the input of a textbox that the user type (can be a richTextBox or something from Infragistics, whatever, as long as it works).
I already tried to separate the string from the split textbox and detect which ones start with @. But after that, I couldn’t color the letters and send them back to the textbox.
I also tried something with the richTextBox selectionColor, but the selection erased the @ and the cursor went to the left of the inserted character, and I could not "stop" the selection when I wanted.
I’m taking a look at Regex to see if I can apply to my problem.
I’m using C# in Visual Studio Community 2017.
EDIT
I changed the code in the comments to try to make it work in my case, but the limiter doesn’t work. I believe this is because the selection starts only from a@, but there may be a ' before, hence Buga.
private void richTextBox1_TextChanged(object sender, EventArgs e)
{
int current = richTextBox1.SelectionStart;
for (int i = 0; i < richTextBox1.Lines.Length; i++)
{
string line = richTextBox1.Lines[i];
int index = line.IndexOf(' '), lineFirstIndex = line.IndexOf('@');
if (index != -1 && lineFirstIndex != -1)
{
richTextBox1.Select(lineFirstIndex, index);
richTextBox1.SelectionColor = Color.Red;
}
else
{
lineFirstIndex = richTextBox1.GetFirstCharIndexFromLine(i);
richTextBox1.Select(lineFirstIndex, line.Length);
richTextBox1.SelectionColor = Color.Empty;
}
}
richTextBox1.Select(current, 0);
}
Out of curiosity: you asked this in Soen too, right?
– Jéf Bueno
I asked you kkk
– Eduardo Remor
Ah, good. I had her open to leave a comment, but here it’s even better. Anyway, you need to give us a little more detail and show us what you’ve tried.
– Jéf Bueno
I’ll edit the post then. It’s the first time I’m posting here kk
– Eduardo Remor
Would that be about right? https://answall.com/questions/268162/colorir-palavra-at%C3%A9-a-limiter
– Valdeir Psr
I put the code on Edit
– Eduardo Remor