如何选择文本框中的所有文本 [英] how select all text in textbox

查看:133
本文介绍了如何选择文本框中的所有文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello All



i有windows App

一些文本框

i tab in textbox by this code < br $>


Hello All

i have windows App
some text boxs
i tab between textbox by this code

private void AstTxt_KeyDown(object sender, KeyEventArgs e)
  {
     if (e.KeyCode == Keys.Enter)
      {
         AltTxt.Focus();

       } 
   }







但我想要什么时候去下一个文本框

选择此文本框中的数据而不删除它




but i want when go next text box
select data in this textbox not delete it

推荐答案

您好,

尝试以下操作:

Hello,
try the following:
private void AstTxt_KeyDown(object sender, KeyEventArgs e)
  {
     if (e.KeyCode == Keys.Enter)
      {
         AltTxt.Focus();

         AltTxt.SelectionStart = 0;
         AltTxt.SelectionLength = AltText.Text.Length;

       } 
   }


TextBox,在焦点 [ ^ ]事件不会删除其中的文本。它只是将焦点从其他控件改为此。



其次,要在TextBox中选择整个文本,可以使用Selection(选择开始 [ ^ ]和 SelectionLength [ ^ ])属性,用于输入要在当前选择中选择的字符;在MSDN链接上阅读更多内容。由于你想要选择所有这些,试试这个,



TextBox, under Focus[^] event doesn't delete the text inside it. It just changes the focus from other controls, to this one.

Secondly, to select entire text inside the TextBox, you can use the Selection (SelectionStart[^] and SelectionLength[^]) properties, to enter the characters that you want to select in the current selection; read more on MSDN links. Since you want to select all of them, try this,

// Set the focus
AltText.Focus();

// Since beginning; zeroth character
AltTxt.SelectionStart = 0;
// Upto the last character.
AtlTxt.SelectionLength = textbox.Text.Length;





以上代码会在您进入内部时从控件中选择文本。没有代码可以删除它,因此它不会从TextBox中删除任何内容。



Above code would select the text from the control when you're inside it. There is no code to delete it, so it won't delete anything from the TextBox.


这篇关于如何选择文本框中的所有文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆