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. WPF
  4. Highlight Text in Textbox

Highlight Text in Textbox

Scheduled Pinned Locked Moved WPF
com
6 Posts 4 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.
  • B Offline
    B Offline
    butchzn
    wrote on last edited by
    #1

    I am attemptimg to programmatically highlight a selection of text in a textbox. I trying to achieve this by so doing:

    tbxItemUrl.SelectionStart = 0;
    tbxItemUrl.SelectionLength = pageDetailItemSection.tbxItemUrl.Text.Length;
    tbxItemUrl.SelectionBackground = new SolidColorBrush(Colors.Yellow);
    tbxItemUrl.SelectionForeground= new SolidColorBrush(Colors.Black);

    but to no avail. some resources...i have attempted to try [][^] Has anybody successfully managed to do this...thanks

    A M C 3 Replies Last reply
    0
    • B butchzn

      I am attemptimg to programmatically highlight a selection of text in a textbox. I trying to achieve this by so doing:

      tbxItemUrl.SelectionStart = 0;
      tbxItemUrl.SelectionLength = pageDetailItemSection.tbxItemUrl.Text.Length;
      tbxItemUrl.SelectionBackground = new SolidColorBrush(Colors.Yellow);
      tbxItemUrl.SelectionForeground= new SolidColorBrush(Colors.Black);

      but to no avail. some resources...i have attempted to try [][^] Has anybody successfully managed to do this...thanks

      A Offline
      A Offline
      Abhinav S
      wrote on last edited by
      #2

      I did not have to search far[^]. Hope it helps !

      There are only 10 types of people in this world — those who understand binary, and those who don't.

      modified on Friday, January 8, 2010 1:02 PM

      1 Reply Last reply
      0
      • B butchzn

        I am attemptimg to programmatically highlight a selection of text in a textbox. I trying to achieve this by so doing:

        tbxItemUrl.SelectionStart = 0;
        tbxItemUrl.SelectionLength = pageDetailItemSection.tbxItemUrl.Text.Length;
        tbxItemUrl.SelectionBackground = new SolidColorBrush(Colors.Yellow);
        tbxItemUrl.SelectionForeground= new SolidColorBrush(Colors.Black);

        but to no avail. some resources...i have attempted to try [][^] Has anybody successfully managed to do this...thanks

        M Offline
        M Offline
        Mark Salsbery
        wrote on last edited by
        #3

        Also, your code probably didn't work because the TextBox didn't have focus. This worked for me:

        System.Windows.Browser.HtmlPage.Plugin.Focus();
        tbxItemUrl.SelectionStart = 0;
        tbxItemUrl.SelectionLength = tbxItemUrl.Text.Length;
        tbxItemUrl.SelectionBackground = new SolidColorBrush(Colors.Yellow);
        tbxItemUrl.SelectionForeground = new SolidColorBrush(Colors.Black);
        tbxItemUrl.Focus();

        Mark Salsbery Microsoft MVP - Visual C++ :java:

        B 1 Reply Last reply
        0
        • M Mark Salsbery

          Also, your code probably didn't work because the TextBox didn't have focus. This worked for me:

          System.Windows.Browser.HtmlPage.Plugin.Focus();
          tbxItemUrl.SelectionStart = 0;
          tbxItemUrl.SelectionLength = tbxItemUrl.Text.Length;
          tbxItemUrl.SelectionBackground = new SolidColorBrush(Colors.Yellow);
          tbxItemUrl.SelectionForeground = new SolidColorBrush(Colors.Black);
          tbxItemUrl.Focus();

          Mark Salsbery Microsoft MVP - Visual C++ :java:

          B Offline
          B Offline
          butchzn
          wrote on last edited by
          #4

          Thanks for the replies. Really appreciated. The focus definitely works, thank you, however i have multiple textboxes that i am looking for matches in and would like to highlight any matches in all the necessary textboxes. Setting the focus would only then highlight 1 textbox. Any suggestions would be welcome. Thanks again.

          M 1 Reply Last reply
          0
          • B butchzn

            Thanks for the replies. Really appreciated. The focus definitely works, thank you, however i have multiple textboxes that i am looking for matches in and would like to highlight any matches in all the necessary textboxes. Setting the focus would only then highlight 1 textbox. Any suggestions would be welcome. Thanks again.

            M Offline
            M Offline
            Mark Salsbery
            wrote on last edited by
            #5

            You'll need to do highlighting something like Abhinav S linked to above.

            Mark Salsbery Microsoft MVP - Visual C++ :java:

            1 Reply Last reply
            0
            • B butchzn

              I am attemptimg to programmatically highlight a selection of text in a textbox. I trying to achieve this by so doing:

              tbxItemUrl.SelectionStart = 0;
              tbxItemUrl.SelectionLength = pageDetailItemSection.tbxItemUrl.Text.Length;
              tbxItemUrl.SelectionBackground = new SolidColorBrush(Colors.Yellow);
              tbxItemUrl.SelectionForeground= new SolidColorBrush(Colors.Black);

              but to no avail. some resources...i have attempted to try [][^] Has anybody successfully managed to do this...thanks

              C Offline
              C Offline
              carlecomm
              wrote on last edited by
              #6

              Check this: http://forums.silverlight.net/forums/p/137089/306336.aspx

              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