I’m trying to use the SelectionStart and SelectionLength properties for a textbox. It is having no effect, but there are no errors either. It’s actually part of a background worker ProgressChanged method, but I’ve tried the SelectionStart and SelectionLength in isolation in a test solution and it is the same.. nothing happens..
Any ideas? Thanks!!!
private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
// Update the GUI as the music is playing
textBox1.SelectionStart = ((int)e.UserState);
textBox1.SelectionLength = (1);
}
Your code as is works fine for me (I’m assuming your BGW is started and you’re calling
ReportProgressof course).My guess here is that your code is working for you too, but perhaps your TextBox doesn’t have focus so you can’t see the selected text.
If this is your problem, set the TextBox’s
HideSelectionproperty to false. This will allow the TextBox’s selected text to display selected (highlighted) even if the TextBox doesn’t have focus.You can also query your TextBox’s SelectedText property to get the control’s selected text, even if it isn’t displayed as such.