How can I select all the text within a Windows Forms textbox? [closed]

て烟熏妆下的殇ゞ 提交于 2019-12-03 05:03:24

You can use the built in method for this purpose.

textBoxResults.SelectAll();
textBoxResults.Focus(); //you need to call this to show selection if it doesn't has focus

You can also try the following which might solve you problem:

textBoxResults.SelectAll();

This works well with multi-lined textbox.

This method enables you to select all text within the control.

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();
}

Check this link for more info. http://msdn.microsoft.com/en-us/library/system.windows.forms.textboxbase.selectall.aspx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!