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. RichTextBox Fun?

RichTextBox Fun?

Scheduled Pinned Locked Moved C#
databasegraphicsquestionworkspace
3 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.
  • I Offline
    I Offline
    IceWater42
    wrote on last edited by
    #1

    The following code works just fine on my "test" form, but when i put the code in the REAL application i get a selection rectangle, rather than the nice text color change i get with this code: richTextBox1.AppendText("This" + System.Environment.NewLine); richTextBox1.AppendText("seems" + System.Environment.NewLine); richTextBox1.AppendText("to" + System.Environment.NewLine); richTextBox1.AppendText("work." + System.Environment.NewLine); string mySearchLetters = textBox1.Text; int index = richTextBox1.Find(mySearchLetters); label1.Text = mySearchLetters + " was found in pos " + index.ToString(); if (index >= 0) richTextBox1.SelectionColor = System.Drawing.Color.Orange; I'm thinking that maybe there is a "property" set on the real application that prevents this code from working but i can not find it. i compare the control properties, line-for-line and they seem to be identical. Any ideas?

    D 1 Reply Last reply
    0
    • I IceWater42

      The following code works just fine on my "test" form, but when i put the code in the REAL application i get a selection rectangle, rather than the nice text color change i get with this code: richTextBox1.AppendText("This" + System.Environment.NewLine); richTextBox1.AppendText("seems" + System.Environment.NewLine); richTextBox1.AppendText("to" + System.Environment.NewLine); richTextBox1.AppendText("work." + System.Environment.NewLine); string mySearchLetters = textBox1.Text; int index = richTextBox1.Find(mySearchLetters); label1.Text = mySearchLetters + " was found in pos " + index.ToString(); if (index >= 0) richTextBox1.SelectionColor = System.Drawing.Color.Orange; I'm thinking that maybe there is a "property" set on the real application that prevents this code from working but i can not find it. i compare the control properties, line-for-line and they seem to be identical. Any ideas?

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      I take it your trying to highlight the position and length of the string you typed in? This code won't work because your not changing the .SelectStart and .SelectionLength properties to actually select the string you want to change with .SelectionColor.

      richTextBox1.SelectionStart = pos;
      richTextBox1.SelectionLength = mySearchLetters.Length;
      richTextBox1.SelectionColor = Color.Orange;
      

      RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

      I 1 Reply Last reply
      0
      • D Dave Kreskowiak

        I take it your trying to highlight the position and length of the string you typed in? This code won't work because your not changing the .SelectStart and .SelectionLength properties to actually select the string you want to change with .SelectionColor.

        richTextBox1.SelectionStart = pos;
        richTextBox1.SelectionLength = mySearchLetters.Length;
        richTextBox1.SelectionColor = Color.Orange;
        

        RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

        I Offline
        I Offline
        IceWater42
        wrote on last edited by
        #3

        It turns out the solution was even simpler .. there WAS a property that was messing things up. All i had to do was set HideSelection to true !!! The pretty orange text was hidden under the selection rectangle ... go figure ... lol. Thanks for responding, Dave.

        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