SelectionColor in RichTextBox when minimized
-
Hi I have the code below to minimize my form to the systemtray and bring it back up when the notifyicon is doubleclicked. When the form is minimized some log-information is added in a richtextbox and I want the errors to be shown in red, so I set the selectioncolor to red. My problem is that this only works if the form is in it's normal state otherwise all the text added will be black. Does anyone know why I can't set the selectioncolor when the form is minimized?
private delegate void UpdateInfoDelegate(string newEvent, Color c);
private void UpdateInfo(string newEvent, Color c)
{
rtbInfo.SelectionColor = c;
rtbInfo.AppendText(newEvent);
rtbInfo.SelectionColor = Color.Black;
}public void SetInfoText(string text)
{
rtbInfo.Invoke(new UpdateInfoDelegate(UpdateInfo), DateTime.Now + " " + text + "\r\n", Color.Black);
}public void SetErrorText(string text)
{
rtbInfo.Invoke(new UpdateInfoDelegate(UpdateInfo), DateTime.Now + " " + text + "\r\n", Color.Red);
}private void Form1_Resize(object sender, EventArgs e)
{
if (WindowState == FormWindowState.Minimized)
{
Hide();
notifyIcon1.Visible = true;
}
}private void notifyIcon1_DoubleClick(object sender, EventArgs e)
{
Show();
WindowState = FormWindowState.Normal;
notifyIcon1.Visible = false;
}http://johanmartensson.se - Home of MPEG4Watcher
-
Hi I have the code below to minimize my form to the systemtray and bring it back up when the notifyicon is doubleclicked. When the form is minimized some log-information is added in a richtextbox and I want the errors to be shown in red, so I set the selectioncolor to red. My problem is that this only works if the form is in it's normal state otherwise all the text added will be black. Does anyone know why I can't set the selectioncolor when the form is minimized?
private delegate void UpdateInfoDelegate(string newEvent, Color c);
private void UpdateInfo(string newEvent, Color c)
{
rtbInfo.SelectionColor = c;
rtbInfo.AppendText(newEvent);
rtbInfo.SelectionColor = Color.Black;
}public void SetInfoText(string text)
{
rtbInfo.Invoke(new UpdateInfoDelegate(UpdateInfo), DateTime.Now + " " + text + "\r\n", Color.Black);
}public void SetErrorText(string text)
{
rtbInfo.Invoke(new UpdateInfoDelegate(UpdateInfo), DateTime.Now + " " + text + "\r\n", Color.Red);
}private void Form1_Resize(object sender, EventArgs e)
{
if (WindowState == FormWindowState.Minimized)
{
Hide();
notifyIcon1.Visible = true;
}
}private void notifyIcon1_DoubleClick(object sender, EventArgs e)
{
Show();
WindowState = FormWindowState.Normal;
notifyIcon1.Visible = false;
}http://johanmartensson.se - Home of MPEG4Watcher
You have to do the append/coloring in this order: append, select appended text, set selection color. See this post on MSDN[^].