zoukankan      html  css  js  c++  java
  • 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();
    }
    
  • 相关阅读:
    POJ2524+并查集
    POJ3697+BFS+hash存边
    POJ1151+线段树+扫描线
    POJ2528+线段树
    ubuntu 和 win7 远程登陆 + vnc登陆
    POJ3690+位运算
    POJ3283+字典树
    POJ3282+模拟
    POJ2349+prim
    2016.6.13
  • 原文地址:https://www.cnblogs.com/sntetwt/p/9897630.html
Copyright © 2011-2022 走看看