Highlight Text in Textbox
-
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
-
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
-
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
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:
-
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:
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.
-
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.
You'll need to do highlighting something like Abhinav S linked to above.
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
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