Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. SelectionColor in RichTextBox when minimized

SelectionColor in RichTextBox when minimized

Scheduled Pinned Locked Moved C#
helpquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Johan Martensson
    wrote on last edited by
    #1

    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

    B 1 Reply Last reply
    0
    • J Johan Martensson

      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

      B Offline
      B Offline
      bcool63303
      wrote on last edited by
      #2

      You have to do the append/coloring in this order: append, select appended text, set selection color. See this post on MSDN[^].

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups