WPF模拟键盘输入和删除

WPF模拟键盘输入和删除

private void ButtonNumber_Click(object sender, RoutedEventArgs e)
{
Button btn = (Button)sender;
string number = btn.Content.ToString();
string keyword = txtKeyword.Text; //已经存在点"."
if (keyword.Contains(".") && number.Equals("."))
{
txtKeyword.Focus();
return;
}
//当前焦点位置
int start = txtKeyword.SelectionStart;
//焦点后面添加内容
if (Common.Utils.isNumber(number) || number.Equals("."))
{
txtKeyword.Text = keyword.Insert(start, number);
txtKeyword.SelectionStart = (start + number.Length);
}
else
{
//删除焦点前面的内容
if (start > 0)
{
txtKeyword.Text = txtKeyword.Text.Remove(start - 1, 1);
txtKeyword.SelectionStart = start - 1;
}
}
txtKeyword.Focus();
}
上一篇:splay模板(BZOJ3224)


下一篇:spark分组统计及二次排序案例一枚