每个我所面临的问题。我正处于初级阶段。如果是愚蠢的问题请忽略。我使用"InputPrompt“控件(从编写有趣的工具包)到以电话号码的形式获取值。当我尝试以123-345-6789的形式输入数字时,光标的位置发生了变化,并返回到以前的值。守则是:
//活动
input.TextInputStart += new TextCompositionEventHandler(input_TextInputStart);
//事件处理程序
void input_TextInputStart(object sender, TextCompositionEventArgs e)
{
if(input.value.lenght == 2)
{
input.value += '-';
}
if(input.value.lenght == 5)
{
input.value += '-';
}
if(input.value.lenght == 9)
{
input.value += '-';
}
}
发布于 2013-08-20 07:38:57
输入提示符不允许像textbox这样的属性,例如选择、设置光标位置等,因此我们需要创建自定义控件,以掩蔽电话号码,这里是一个告诉自定义控件的链接。Link
发布于 2013-08-19 09:11:02
你需要这个:
TextBox.SelectionStart(int start,int end);
如果你这样做:
void input_TextInputStart(object sender, TextCompositionEventArgs e)
{
if(input.value.lenght == 2)
{
input.value += '-';.
input.SelectionStart(input.Length-1,input.Length-1);
}
if(input.value.lenght == 5)
{
input.value += '-';
input.SelectionStart(input.Length-1,input.Length-1);
}
if(input.value.lenght == 9)
{
input.value += '-';
input.SelectionStart(input.Length-1,input.Length-1);
}
}
可能语法不正确,但方法是您所需要的。
发布于 2013-11-26 08:55:14
也可以从InputPrompt类派生,并使TextBox属性公开,类似于:
public class MyInputPrompt : InputPrompt
{
public TextBox MyInputBox
{
get { return this.InputBox; }
set
{
if (value != this.InputBox)
{
this.InputBox = value;
}
}
}
}
https://stackoverflow.com/questions/18310008
复制相似问题