I am using a WFA which has a ToolStripMenuItem that is supposed to search for a word in a textBox and highlight it. This is the highlighting code.
first = first index to be highlighted
, length= number of characters to be highlighted.
textBox2.SelectionStart = first;
textBox2.SelectionLength = length;
//scroll to the caret
textBox2.ScrollToCaret();
everything seems to be working well. However, If the mouse cursor isn’t inside textBox2 (say in another textBox). The highlighting doesn’t work. Is there a way to make it work regardless of the position of the mouse cursor? in other words, is there a way to change my code to make it highlight the text in textBox2 even if the mouse cursor wasn’t inside textBox2 before hitting the ToolStripMenuItem?
P.S. It’s worth mentioning that I am using c# in VS 2010
Try:
before you run the code that highlights the text. This will move input focus (and your cursor) to the textbox