I\'m trying to color parts of a string to be appended to a RichTextBox. I have a string built from different strings.
string temp = \"[\" + DateTime.Now.ToSh
Selecting text as said from somebody, may the selection appear momentarily.
In Windows Forms applications
there is no other solutions for the problem, but today I found a bad, working, way to solve: you can put a PictureBox
in overlapping to the RichtextBox
with the screenshot of if, during the selection and the changing color or font, making it after reappear all, when the operation is complete.
Code is here...
//The PictureBox has to be invisible before this, at creation
//tb variable is your RichTextBox
//inputPreview variable is your PictureBox
using (Graphics g = inputPreview.CreateGraphics())
{
Point loc = tb.PointToScreen(new Point(0, 0));
g.CopyFromScreen(loc, loc, tb.Size);
Point pt = tb.GetPositionFromCharIndex(tb.TextLength);
g.FillRectangle(new SolidBrush(Color.Red), new Rectangle(pt.X, 0, 100, tb.Height));
}
inputPreview.Invalidate();
inputPreview.Show();
//Your code here (example: tb.Select(...); tb.SelectionColor = ...;)
inputPreview.Hide();
Better is to use WPF; this solution isn't perfect, but for Winform it works.