Ich möchte den gesamten Text auswählen, der sich in einem Textfeld befindet.
Ich habe es mit dem folgenden Code versucht:
textBoxResults.SelectionStart = 0;
textBoxResults.SelectionLength = textBoxResults.Text.Length;
Quelle: Ich habe diesen Code von hier aus http://msdn.Microsoft.com/de-de/library/vstudio/hk09zy8f(v=vs.100).aspx Es scheint zu funktionieren.
Sie können dafür die integrierte Methode verwenden.
textBoxResults.SelectAll();
textBoxResults.Focus(); //you need to call this to show selection if it doesn't has focus
Mit dieser Methode können Sie den gesamten Text im Steuerelement auswählen.
public void CopyAllMyText()
{
// Determine if any text is selected in the TextBox control.
if(textBox1.SelectionLength == 0)
// Select all text in the text box.
textBox1.SelectAll();
// Copy the contents of the control to the Clipboard.
textBox1.Copy();
}
Überprüfen Sie diesen Link für weitere Informationen. http://msdn.Microsoft.com/de-de/library/system.windows.forms.textboxbase.selectall.aspx
Sie können auch Folgendes versuchen, um das Problem zu lösen:
textBoxResults.SelectAll();
Dies funktioniert gut mit mehrzeiliger Textbox.