【发布时间】:2013-07-04 04:50:00
【问题描述】:
我有一个带面具的货币Textbox。
掩码在textbox 中显示为--------.--
所以用户在掩码上输入数字。
现在客户说他不想从左到右输入字母。 他想从右到左打字。
类似于我们的计算器。
现在我尝试更改 textbox 的 righttoleft 属性,但这对我的事业没有帮助。
最后,我坚持处理关键事件以手动更改位置。 我可以更改位置,但在完成逻辑时遇到了困难。
我的代码如下所示:
void Textbx_KeyDown(object sender, KeyEventArgs e)
{
String temp = T.Text;
string temp2 = T.Text;
int CursorIndex = T.SelectionStart - 1;
for (int i = 0; i <= CursorIndex; i++)
{
if (i == 7)
{
temp2 = temp2.Insert(i, temp[i + 2].ToString());
temp2 = temp2.Remove(i, 2);
//i = i + 2;
}
else if (CursorIndex == i)
{
temp2 = temp2.Remove(i, 1);
temp2 = temp2.Insert(i, temp[i + 1].ToString());
}
else
{
// T.Text = T.Text.Insert(i + 1, "_");
temp2 = temp2.Insert(i, temp[i + 1].ToString());
temp2 = temp2.Remove(i + 1, 1);
}
}
T.Text = temp2;
// T.Text = T.Text.Insert(CursorIndex-1, temp[CursorIndex].ToString());
if (CursorIndex != -1)
T.SelectionStart = CursorIndex - 1;
}
有没有更好的方法来做到这一点?如果不是,我应该如何完成逻辑?
【问题讨论】:
标签: c# .net winforms textbox maskedtextbox