when i change text color at RTB by SelectionColor, i see the selection flickering.
how can prevent the RTB from updating view, until i finish coloring?
Printable View
when i change text color at RTB by SelectionColor, i see the selection flickering.
how can prevent the RTB from updating view, until i finish coloring?
what are you trying to do?
give us more details about what you're doing.
My question:
Is there another way to color text on rich text box, without using SelectionColor(,)?
Coloring text with SelectionColor() is not good enough, because its take too much time, and i see the text selected and unselected.
I have lot of text to color and it take many seconds till it finish.
you may try out,
richTextBox1.Focus();
richTextBox1.SelectionColor = Color.Red;
richTextBox1.SelectionFont = new Font ("Courier", 10, FontStyle.Bold);
try
{
int start = richTextBox1.SelectionStart;
int len = richTextBox1.SelectionLength;
System.Drawing.Font currentFont;
FontStyle fs;
for(int i = 0; i < len; ++i)
{
richTextBox1.Select(start + i, 1);
currentFont = richTextBox1.SelectionFont;
fs = currentFont.Style;
//add style
fs = fs | style;
richTextBox1.SelectionFont = new Font(
currentFont.FontFamily,
currentFont.Size,
fs
);
}
}
private void RemoveFontStyle(FontStyle style)
{
int start = richTextBox1.SelectionStart;
int len = richTextBox1.SelectionLength;
System.Drawing.Font currentFont;
FontStyle fs;
for(int i = 0; i < len; ++i)
{
richTextBox1.Select(start + i, 1);
currentFont = richTextBox1.SelectionFont;
fs = currentFont.Style;
//remove style
fs = fs & ~style;
richTextBox1.SelectionFont = new Font(
currentFont.FontFamily,
currentFont.Size,
fs
);
}
}
private void button1_Click(object sender, System.EventArgs e)
{
AddFontStyle(FontStyle.Bold);
}