正确验证文本 [英] Proper validation for text

查看:79
本文介绍了正确验证文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我插入文本作为成员的名字现在我已经为第一个字母的大小写做了一些代码...但问题是,当我尝试在另外两个单词之间插入新单词时,光标移到最后一个字母的末尾每当我按下钥匙的话......



我处理以下代码......



< b>我尝试过:



CultureInfo cultureInfo = System.Threading.Thread.CurrentThread.CurrentCulture;

TextInfo textInfo = cultureInfo.TextInfo;

tbOwnerName.Text = textInfo.ToTitleCase(tbOwnerName.Text.ToLower());

tbOwnerName.Select(tbOwnerName.Text.Length,0) ;

Im inserting text as a name of member now I've done some code for capitalization of 1st letter...but the problem is that as I try to insert new word between two other words the cursor goes to end of the last word whenever I press the key...

Im dealing with following code...

What I have tried:

CultureInfo cultureInfo = System.Threading.Thread.CurrentThread.CurrentCulture;
TextInfo textInfo = cultureInfo.TextInfo;
tbOwnerName.Text = textInfo.ToTitleCase(tbOwnerName.Text.ToLower());
tbOwnerName.Select(tbOwnerName.Text.Length, 0);

推荐答案

查看TextBox.SelectionStart属性 - 在执行文本Set之前获取它,然后再次设置它。 SelectionStart属性将双精度设置为插入位置,以便保持用户输入位置。
Look at the TextBox.SelectionStart property - fetch it before you do the text Set, and set it again afterwards. The SelectionStart property sets doubles up as the caret position, so that will maintain the user input position.


这篇关于正确验证文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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