将插入符号位置设置为屏蔽文本框中的最后一个字符 - winform? [英] set caret position to last character in masked text box - winform?

查看:22
本文介绍了将插入符号位置设置为屏蔽文本框中的最后一个字符 - winform?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个输入掩码为 A-00-000-0000 的掩码文本框
它从数据库中获取数据.喜欢

I have a masked textbox with input mask as A-00-000-0000
It gets data from database. Like

有没有办法将插入符号位置设置为上述特定位置?

Is there any way to set caret position to specific position as mentioned above?

推荐答案

优化我的代码后,我的逻辑是将插入符号移动到所需位置,独立于掩码,并在该位置之后删除字符串..

After optimizing my codes, my logic is to move caret at desired location, independen of mask, And remove string after that location..

''' <summary>
'''  Set Caret Position to specific location and remove data After given Location
''' </summary>
''' <param name="MaskedTb"> Masked textbox</param>
''' <param name="Loct99">Location (Index) after which remove occured and caret is set</param>
''' <remarks></remarks>
Public Sub FocsToMaskedTb( MaskedTb As MaskedTextBox, ByVal Loct99 As Integer)
    If MaskedTb.Text.Length >= Loct99 Then
        MaskedTb.Text = MaskedTb.Text.Remove(Loct99)
    End If
    MaskedTb.SelectionStart = MaskedTb.MaskedTextProvider.LastAssignedPosition + 1
    '' I am using MaskedTextProvider Property
    '' If there is nothing in TextBox, MaskedTb.MaskedTextProvider.LastAssignedPosition = -1
End Sub

这篇关于将插入符号位置设置为屏蔽文本框中的最后一个字符 - winform?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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