在文本框的任何文本的末尾设置光标 [英] Setting cursor at the end of any text of a textbox

查看:142
本文介绍了在文本框的任何文本的末尾设置光标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有已在其显示的字符串的文本框。
将光标来我已经在做文本

I have a text box with a displayed string already in it. To bring the cursor to the textbox I am already doing

txtbox.Focus();



但我怎么让光标在文本框中的字符串的结束?

But how do I get the cursor at the end of the string in the textbox ?

推荐答案

您可以控制 txtbox.SelectionStart 光标位置(和选择)和 txtbox.SelectionLength 属性。如果您想设置插入符结束试试这个:

You can control cursor position (and selection) with txtbox.SelectionStart and txtbox.SelectionLength properties. If you want to set caret to end try this:

txtbox.SelectionStart = txtbox.Text.Length -1 // add some logic if length is 0
txtbox.SelectionLength = 0

有关WPF看到的this帖子

这篇关于在文本框的任何文本的末尾设置光标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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