• C#实现软键盘的制作


    在工控机上完成,触摸屏,包括键盘输入。此时需要一个软键盘,只完成的输入就可以,但是操作系统自带的软键盘是包含非数字内容,且占用面积大。因此需要自己写一个软键盘的程序,在有数字输入的时候调用显示即可。本文讲解C#软键盘的制作
    1、每次按完按键之后光标显示在最上面的文本框中,这里文本框为textbox。

    这个问题我在编写之前并没有发现,可当用的时候发现,如果不进行设置,在点击按钮之后,文本框中根本没有光标。这样在输入空格的时候根本就不知道输入到哪了。那么这个应该怎么做呢?

    [DllImport(“USER32.DLL”)]
    public static extern IntPtr FindWindow(string lpClassName, string lpWindowName); //导入寻找windows窗体的方法
    [DllImport(“USER32.DLL”)]
    public static extern bool SetForegroundWindow(IntPtr hWnd); //导入为windows窗体设置焦点的方法
    在窗体类中加入上面代码。本程序中窗体类指的是:public partial class Edit : Form。这个下面,所有的winform窗体都会有一个类继承form类。

    然后在每个按钮的点击方法中加入下列语句:

    textBox.Focus();
    //设置光标的位置到文本尾
    textBox.Select(textBox.Text.Length, 0);
    //滚动到控件光标处
    textBox.ScrollToCaret();
    这样,在点击按钮后会发现光标会在textbox中了。
    在这里插入图片描述
    2、backspace按键

    在做到backspace按键的时候,怎么才能删除文本框中的内容,像我们电脑的键盘一样呢?跟1中的相似。首先在窗体类中加入下述代码:

    [DllImport(“USER32.DLL”)]
    public static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo); //导入模拟键盘的方法
    接下来,下backspace按键的点击方法中加入下列代码:

    SendKeys.Send(“{BACKSPACE}”);
    这个是使这个按钮模拟电脑上的backspace按键的功能。可能有人会有疑惑,我怎么知道我删除的是哪里的内容。因为每次我们在按键的时候都是将光标放在了textbox的末尾,所以每次删除的都是textbox中的内容。

    3、caps lock 和 shift功能

    这个我实现的方法是在文本框的下面添加两个lable,caps和shift各一个,用来显示两个按键是否按下。默认设置为不可见。也就是 Label_Shift.Visible = false;

    然后设置两个标志位,如下

    private bool Shift = false;

    private bool Caps_Lock = false;

    这里举一个例子,shift按钮:代码如下:

    private void button_shift_Click(object sender, EventArgs e)
    {
    switch (Shift)
    {
    case false:
    {
    Label_Shift.Visible = true;
    Shift = true;
    break;
    }
    case true:
    {
    Label_Shift.Visible = false;
    Shift = false;
    break;
    }
    }
    textBox.Focus();
    //设置光标的位置到文本尾
    textBox.Select(textBox.Text.Length, 0);
    //滚动到控件光标处
    textBox.ScrollToCaret();
    }
    这里右shift和caps lock的是一样的。这里就不在多说了。

    办法笨了一些,但是比较简单,适用于初学者,速度还可以。

    效果图如下:
    在这里插入图片描述
    详细程序如下所示
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.Runtime.InteropServices;

    namespace KeyBoad
    {
    public partial class Edit : Form
    {
    //private const int WS_EX_TOOLWINDOW = 0x00000080;
    //private const int WS_EX_NOACTIVATE = 0x08000000;

        private bool Shift = false;
        private bool Caps_Lock = false;
    
        [DllImport("USER32.DLL")]
        public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);  //导入寻找windows窗体的方法
        [DllImport("USER32.DLL")]
        public static extern bool SetForegroundWindow(IntPtr hWnd);  //导入为windows窗体设置焦点的方法
        [DllImport("USER32.DLL")]
        public static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);  //导入模拟键盘的方法
    
        public string get_textBox()
        {
            return textBox.Text;
        }
    
        public Edit()
        {
            InitializeComponent();
        }
    
        public Edit(string name, string text)
        {
            InitializeComponent();
            textBox.Text = text;
            label1.Text = name;
            if ("Wafer Id".Equals(name))
            {
                button.Enabled = false;
                button_10.Enabled = false;
                button_11.Enabled = false;
                button_12.Enabled = false;
                button_caps.Enabled = false;
                button_shift.Enabled = false;
                button_shift_right.Enabled = false;
                button_q.Enabled = false;
                button_w.Enabled = false;
                button_e.Enabled = false;
                button_r.Enabled = false;
                button_t.Enabled = false;
                button_y.Enabled = false;
                button_u.Enabled = false;
                button_i.Enabled = false;
                button_o.Enabled = false;
                button_p.Enabled = false;
                button_left.Enabled = false;
                button_right.Enabled = false;
                button_a.Enabled = false;
                button_s.Enabled = false;
                button_d.Enabled = false;
                button_f.Enabled = false;
                button_g.Enabled = false;
                button_h.Enabled = false;
                button_j.Enabled = false;
                button_k.Enabled = false;
                button_l.Enabled = false;
                button_colon.Enabled = false;
                button_quo.Enabled = false;
                button_z.Enabled = false;
                button_x.Enabled = false;
                button_c.Enabled = false;
                button_v.Enabled = false;
                button_b.Enabled = false;
                button_n.Enabled = false;
                button_m.Enabled = false;
                button_comma.Enabled = false;
                button_period.Enabled = false;
                button_question.Enabled = false;
                button_space.Enabled = false;
            }
    
            //=============================================键盘
            button.Text = "~\n、";
            button_1.Text = "!\n1";
            button_2.Text = "@\n2";
            button_3.Text = "#\n3";
            button_4.Text = "$\n4";
            button_5.Text = "%\n5";
            button_6.Text = "^\n6";
            button_7.Text = "&\n7";
            button_8.Text = "*\n8";
            button_9.Text = "(\n9";
            button_0.Text = ")\n0";
            button_10.Text = "_\n-";
            button_11.Text = "+\n=";
            button_12.Text = "|\n\\";
            button_backspace.Text = "Backspace";
    
            button_caps.Text = "Caps Lock";
    
            button_q.Text = "Q";
            button_w.Text = "W";
            button_e.Text = "E";
            button_r.Text = "R";
            button_t.Text = "T";
            button_y.Text = "Y";
            button_u.Text = "U";
            button_i.Text = "I";
            button_o.Text = "O";
            button_p.Text = "P";
            button_left.Text = "{\n[";
            button_right.Text = "}\n]";
    
            button_a.Text = "A";
            button_s.Text = "S";
            button_d.Text = "D";
            button_f.Text = "F";
            button_g.Text = "G";
            button_h.Text = "H";
            button_j.Text = "J";
            button_k.Text = "K";
            button_l.Text = "L";
            button_colon.Text = ":\n;";
            button_quo.Text = "\"\n\'";
    
            button_OK.Text = "OK";
    
            button_shift.Text = "Shift";
            button_z.Text = "Z";
            button_x.Text = "X";
            button_c.Text = "C";
            button_v.Text = "V";
            button_b.Text = "B";
            button_n.Text = "N";
            button_m.Text = "M";
            button_comma.Text = "<\n,";
            button_period.Text = ">\n.";
            button_question.Text = "?\n/";
            button_shift_right.Text = "Shift";
            button_cancel.Text = "Cancel";
    
            button_space.Text = "Space";
            button_clear.Text = "Clear";
        }
    
        private void button_enter_Click(object sender, EventArgs e)
        {
            //text = textBox.Text;
            this.Close();
            textBox.Focus();
            //设置光标的位置到文本尾 
            textBox.Select(textBox.Text.Length, 0);
            //滚动到控件光标处 
            textBox.ScrollToCaret();
        }
    
        private void button_Click(object sender, EventArgs e)
        {
            if (Shift)
                textBox.Text += "~";
            else
                textBox.Text += "`";
            textBox.Focus();
            //设置光标的位置到文本尾 
            textBox.Select(textBox.Text.Length, 0);
            //滚动到控件光标处 
            textBox.ScrollToCaret();
        }
    
        private void button_1_Click(object sender, EventArgs e)
        {
            if (Shift)
                textBox.Text += "!";
            else
                textBox.Text += "1";
            textBox.Focus();
            //设置光标的位置到文本尾 
            textBox.Select(textBox.Text.Length, 0);
            //滚动到控件光标处 
            textBox.ScrollToCaret();
        }
    
        private void button_caps_Click(object sender, EventArgs e)
        {
            switch (Caps_Lock)
            {
                case false:
                    {
                        Label_Caps.Visible = true;
                        Caps_Lock = true;
                        break;
                    }
                case true:
                    {
                        Label_Caps.Visible = false;
                        Caps_Lock = false;
                        break;
                    }
            }
            textBox.Focus();
            //设置光标的位置到文本尾 
            textBox.Select(textBox.Text.Length, 0);
            //滚动到控件光标处 
            textBox.ScrollToCaret();
    
        }
    
        private void button_shift_Click(object sender, EventArgs e)
        {
            switch (Shift)
            {
                case false:
                    {
                        Label_Shift.Visible = true;
                        Shift = true;
                        break;
                    }
                case true:
                    {
                        Label_Shift.Visible = false;
                        Shift = false;
                        break;
                    }
            }
            textBox.Focus();
            //设置光标的位置到文本尾 
            textBox.Select(textBox.Text.Length, 0);
            //滚动到控件光标处 
            textBox.ScrollToCaret();
        }
    
        private void button_shift_right_Click(object sender, EventArgs e)
        {
            switch (Shift)
            {
                case false:
                    {
                        Label_Shift.Visible = true;
                        Shift = true;
                        break;
                    }
                case true:
                    {
                        Label_Shift.Visible = false;
                        Shift = false;
                        break;
                    }
            }
            textBox.Focus();
            //设置光标的位置到文本尾 
            textBox.Select(textBox.Text.Length, 0);
            //滚动到控件光标处 
            textBox.ScrollToCaret();
        }
    
        private void button_cancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    
        private void button_2_Click(object sender, EventArgs e)
        {
            if (Shift)
                textBox.Text += "@";
            else
                textBox.Text += "2";
            textBox.Focus();
            //设置光标的位置到文本尾 
            textBox.Select(textBox.Text.Length, 0);
            //滚动到控件光标处 
            textBox.ScrollToCaret();
        }
    
        private void button_3_Click(object sender, EventArgs e)
        {
            if (Shift)
                textBox.Text += "#";
            else
                textBox.Text += "3"; textBox.Focus();
            //设置光标的位置到文本尾 
            textBox.Select(textBox.Text.Length, 0);
            //滚动到控件光标处 
            textBox.ScrollToCaret();
        }
    
        private void button_4_Click(object sender, EventArgs e)
        {
            if (Shift)
                textBox.Text += "$";
            else
                textBox.Text += "4"; textBox.Focus();
            //设置光标的位置到文本尾 
            textBox.Select(textBox.Text.Length, 0);
            //滚动到控件光标处 
            textBox.ScrollToCaret();
        }
    
        private void button_5_Click(object sender, EventArgs e)
        {
            if (Shift)
                textBox.Text += "%";
            else
                textBox.Text += "5"; textBox.Focus();
            //设置光标的位置到文本尾 
            textBox.Select(textBox.Text.Length, 0);
            //滚动到控件光标处 
            textBox.ScrollToCaret();
        }
    
        private void button_6_Click(object sender, EventArgs e)
        {
            if (Shift)
                textBox.Text += "^";
            else
                textBox.Text += "6"; textBox.Focus();
            //设置光标的位置到文本尾 
            textBox.Select(textBox.Text.Length, 0);
            //滚动到控件光标处 
            textBox.ScrollToCaret();
        }
    
        private void button_7_Click(object sender, EventArgs e)
        {
            if (Shift)
                textBox.Text += "&";
            else
                textBox.Text += "7"; textBox.Focus();
            //设置光标的位置到文本尾 
            textBox.Select(textBox.Text.Length, 0);
            //滚动到控件光标处 
            textBox.ScrollToCaret();
        }
    
        private void button_8_Click(object sender, EventArgs e)
        {
            if (Shift)
                textBox.Text += "*";
            else
                textBox.Text += "8"; textBox.Focus();
            //设置光标的位置到文本尾 
            textBox.Select(textBox.Text.Length, 0);
            //滚动到控件光标处 
            textBox.ScrollToCaret();
        }
    
        private void button_9_Click(object sender, EventArgs e)
        {
            if (Shift)
                textBox.Text += "(";
            else
                textBox.Text += "9"; textBox.Focus();
            //设置光标的位置到文本尾 
            textBox.Select(textBox.Text.Length, 0);
            //滚动到控件光标处 
            textBox.ScrollToCaret();
        }
    
        private void button_0_Click(object sender, EventArgs e)
        {
            if (Shift)
                textBox.Text += ")";
            else
                textBox.Text += "0"; textBox.Focus();
            //设置光标的位置到文本尾 
            textBox.Select(textBox.Text.Length, 0);
            //滚动到控件光标处 
            textBox.ScrollToCaret();
        }
    
        private void button_10_Click(object sender, EventArgs e)
        {
            if (Shift)
                textBox.Text += "_";
            else
                textBox.Text += "-"; textBox.Focus();
            //设置光标的位置到文本尾 
            textBox.Select(textBox.Text.Length, 0);
            //滚动到控件光标处 
            textBox.ScrollToCaret();
        }
    
        private void button_11_Click(object sender, EventArgs e)
        {
            if (Shift)
                textBox.Text += "+";
            else
                textBox.Text += "="; textBox.Focus();
            //设置光标的位置到文本尾 
            textBox.Select(textBox.Text.Length, 0);
            //滚动到控件光标处 
            textBox.ScrollToCaret();
        }
    
        private void button_12_Click(object sender, EventArgs e)
        {
            if (Shift)
                textBox.Text += "|";
            else
                textBox.Text += "\\"; textBox.Focus();
            //设置光标的位置到文本尾 
            textBox.Select(textBox.Text.Length, 0);
            //滚动到控件光标处 
            textBox.ScrollToCaret();
        }
    
        private void button_backspace_Click(object sender, EventArgs e)
        {
            textBox.Focus();
            //设置光标的位置到文本尾 
            textBox.Select(textBox.Text.Length, 0);
            //滚动到控件光标处 
            textBox.ScrollToCaret();
            SendKeys.Send("{BACKSPACE}");
        }
    
        private void button_q_Click(object sender, EventArgs e)
        {
            if (!(Caps_Lock ^ Shift))
                textBox.Text += "q";
            else
                textBox.Text += "Q"; textBox.Focus();
            //设置光标的位置到文本尾 
            textBox.Select(textBox.Text.Length, 0);
            //滚动到控件光标处 
            textBox.ScrollToCaret();
        }
    
        private void button_w_Click(object sender, EventArgs e)
        {
            if (!(Caps_Lock ^ Shift))
                textBox.Text += "w";
            else
                textBox.Text += "W"; textBox.Focus();
            //设置光标的位置到文本尾 
            textBox.Select(textBox.Text.Length, 0);
            //滚动到控件光标处 
            textBox.ScrollToCaret();
        }
    
        private void button_e_Click(object sender, EventArgs e)
        {
            if (!(Caps_Lock ^ Shift))
                textBox.Text += "e";
            else
                textBox.Text += "E"; textBox.Focus();
            //设置光标的位置到文本尾 
            textBox.Select(textBox.Text.Length, 0);
            //滚动到控件光标处 
            textBox.ScrollToCaret();
        }
    
        private void button_r_Click(object sender, EventArgs e)
        {
            if (!(Caps_Lock ^ Shift))
                textBox.Text += "r";
            else
                textBox.Text += "R"; textBox.Focus();
            //设置光标的位置到文本尾 
            textBox.Select(textBox.Text.Length, 0);
            //滚动到控件光标处 
            textBox.ScrollToCaret();
        }
    
        private void button_t_Click(object sender, EventArgs e)
        {
            if (!(Caps_Lock ^ Shift))
                textBox.Text += "t";
            else
                textBox.Text += "T"; textBox.Focus();
            //设置光标的位置到文本尾 
            textBox.Select(textBox.Text.Length, 0);
            //滚动到控件光标处 
            textBox.ScrollToCaret();
        }
    
        private void button_y_Click(object sender, EventArgs e)
        {
            if (!(Caps_Lock ^ Shift))
                textBox.Text += "y";
            else
                textBox.Text += "Y"; textBox.Focus();
            //设置光标的位置到文本尾 
            textBox.Select(textBox.Text.Length, 0);
            //滚动到控件光标处 
            textBox.ScrollToCaret();
        }
    
        private void button_u_Click(object sender, EventArgs e)
        {
            if (!(Caps_Lock ^ Shift))
                textBox.Text += "u";
            else
                textBox.Text += "U"; textBox.Focus();
            //设置光标的位置到文本尾 
            textBox.Select(textBox.Text.Length, 0);
            //滚动到控件光标处 
            textBox.ScrollToCaret();
        }
    
        private void button_i_Click(object sender, EventArgs e)
        {
            if (!(Caps_Lock ^ Shift))
                textBox.Text += "i";
            else
                textBox.Text += "I"; textBox.Focus();
            //设置光标的位置到文本尾 
            textBox.Select(textBox.Text.Length, 0);
            //滚动到控件光标处 
            textBox.ScrollToCaret();
        }
    
        private void button_o_Click(object sender, EventArgs e)
        {
            if (!(Caps_Lock ^ Shift))
                textBox.Text += "o";
            else
                textBox.Text += "O"; textBox.Focus();
            //设置光标的位置到文本尾 
            textBox.Select(textBox.Text.Length, 0);
            //滚动到控件光标处 
            textBox.ScrollToCaret();
        }
    
        private void button_p_Click(object sender, EventArgs e)
        {
            if (!(Caps_Lock ^ Shift))
                textBox.Text += "p";
            else
                textBox.Text += "P"; textBox.Focus();
            //设置光标的位置到文本尾 
            textBox.Select(textBox.Text.Length, 0);
            //滚动到控件光标处 
            textBox.ScrollToCaret();
        }
    
        private void button_left_Click(object sender, EventArgs e)
        {
            if (Shift)
                textBox.Text += "{";
            else
                textBox.Text += "["; textBox.Focus();
            //设置光标的位置到文本尾 
            textBox.Select(textBox.Text.Length, 0);
            //滚动到控件光标处 
            textBox.ScrollToCaret();
        }
    
        private void button_right_Click(object sender, EventArgs e)
        {
            if (Shift)
                textBox.Text += "}";
            else
                textBox.Text += "]"; textBox.Focus();
            //设置光标的位置到文本尾 
            textBox.Select(textBox.Text.Length, 0);
            //滚动到控件光标处 
            textBox.ScrollToCaret();
        }
    
        private void button_a_Click(object sender, EventArgs e)
        {
            if (!(Caps_Lock ^ Shift))
                textBox.Text += "a";
            else
                textBox.Text += "A"; textBox.Focus();
            //设置光标的位置到文本尾 
            textBox.Select(textBox.Text.Length, 0);
            //滚动到控件光标处 
            textBox.ScrollToCaret();
        }
    
        private void button_s_Click(object sender, EventArgs e)
        {
            if (!(Caps_Lock ^ Shift))
                textBox.Text += "s";
            else
                textBox.Text += "S"; textBox.Focus();
            //设置光标的位置到文本尾 
            textBox.Select(textBox.Text.Length, 0);
            //滚动到控件光标处 
            textBox.ScrollToCaret();
        }
    
        private void button_d_Click(object sender, EventArgs e)
        {
            if (!(Caps_Lock ^ Shift))
                textBox.Text += "d";
            else
                textBox.Text += "D"; textBox.Focus();
            //设置光标的位置到文本尾 
            textBox.Select(textBox.Text.Length, 0);
            //滚动到控件光标处 
            textBox.ScrollToCaret();
        }
    
        private void button_f_Click(object sender, EventArgs e)
        {
            if (!(Caps_Lock ^ Shift))
                textBox.Text += "f";
            else
                textBox.Text += "F"; textBox.Focus();
            //设置光标的位置到文本尾 
            textBox.Select(textBox.Text.Length, 0);
            //滚动到控件光标处 
            textBox.ScrollToCaret();
        }
    
        private void button_g_Click(object sender, EventArgs e)
        {
            if (!(Caps_Lock ^ Shift))
                textBox.Text += "g";
            else
                textBox.Text += "G"; textBox.Focus();
            //设置光标的位置到文本尾 
            textBox.Select(textBox.Text.Length, 0);
            //滚动到控件光标处 
            textBox.ScrollToCaret();
        }
    
        private void button_h_Click(object sender, EventArgs e)
        {
            if (!(Caps_Lock ^ Shift))
                textBox.Text += "h";
            else
                textBox.Text += "H"; textBox.Focus();
            //设置光标的位置到文本尾 
            textBox.Select(textBox.Text.Length, 0);
            //滚动到控件光标处 
            textBox.ScrollToCaret();
        }
    
        private void button_j_Click(object sender, EventArgs e)
        {
            if (!(Caps_Lock ^ Shift))
                textBox.Text += "j";
            else
                textBox.Text += "J"; textBox.Focus();
            //设置光标的位置到文本尾 
            textBox.Select(textBox.Text.Length, 0);
            //滚动到控件光标处 
            textBox.ScrollToCaret();
        }
    
        private void button_k_Click(object sender, EventArgs e)
        {
            if (!(Caps_Lock ^ Shift))
                textBox.Text += "k";
            else
                textBox.Text += "K"; textBox.Focus();
            //设置光标的位置到文本尾 
            textBox.Select(textBox.Text.Length, 0);
            //滚动到控件光标处 
            textBox.ScrollToCaret();
        }
    
        private void button_l_Click(object sender, EventArgs e)
        {
            if (!(Caps_Lock ^ Shift))
                textBox.Text += "l";
            else
                textBox.Text += "L"; textBox.Focus();
            //设置光标的位置到文本尾 
            textBox.Select(textBox.Text.Length, 0);
            //滚动到控件光标处 
            textBox.ScrollToCaret();
        }
    
        private void button_colon_Click(object sender, EventArgs e)
        {
            if (Shift)
                textBox.Text += ":";
            else
                textBox.Text += ";"; textBox.Focus();
            //设置光标的位置到文本尾 
            textBox.Select(textBox.Text.Length, 0);
            //滚动到控件光标处 
            textBox.ScrollToCaret();
        }
    
        private void button_quo_Click(object sender, EventArgs e)
        {
            if (Shift)
                textBox.Text += "\"";
            else
                textBox.Text += "'"; textBox.Focus();
            //设置光标的位置到文本尾 
            textBox.Select(textBox.Text.Length, 0);
            //滚动到控件光标处 
            textBox.ScrollToCaret();
        }
    
    
        private void button_z_Click(object sender, EventArgs e)
        {
            if (!(Caps_Lock ^ Shift))
                textBox.Text += "z";
            else
                textBox.Text += "Z"; textBox.Focus();
            //设置光标的位置到文本尾 
            textBox.Select(textBox.Text.Length, 0);
            //滚动到控件光标处 
            textBox.ScrollToCaret();
        }
    
        private void button_x_Click(object sender, EventArgs e)
        {
            if (!(Caps_Lock ^ Shift))
                textBox.Text += "x";
            else
                textBox.Text += "X"; textBox.Focus();
            //设置光标的位置到文本尾 
            textBox.Select(textBox.Text.Length, 0);
            //滚动到控件光标处 
            textBox.ScrollToCaret();
        }
    
        private void button_c_Click(object sender, EventArgs e)
        {
            if (!(Caps_Lock ^ Shift))
                textBox.Text += "c";
            else
                textBox.Text += "C"; textBox.Focus();
            //设置光标的位置到文本尾 
            textBox.Select(textBox.Text.Length, 0);
            //滚动到控件光标处 
            textBox.ScrollToCaret();
        }
    
        private void button_v_Click(object sender, EventArgs e)
        {
            if (!(Caps_Lock ^ Shift))
                textBox.Text += "v";
            else
                textBox.Text += "V"; textBox.Focus();
            //设置光标的位置到文本尾 
            textBox.Select(textBox.Text.Length, 0);
            //滚动到控件光标处 
            textBox.ScrollToCaret();
        }
    
        private void button_b_Click(object sender, EventArgs e)
        {
            if (!(Caps_Lock ^ Shift))
                textBox.Text += "b";
            else
                textBox.Text += "B"; textBox.Focus();
            //设置光标的位置到文本尾 
            textBox.Select(textBox.Text.Length, 0);
            //滚动到控件光标处 
            textBox.ScrollToCaret();
        }
    
        private void button_n_Click(object sender, EventArgs e)
        {
            if (!(Caps_Lock ^ Shift))
                textBox.Text += "n";
            else
                textBox.Text += "N"; textBox.Focus();
            //设置光标的位置到文本尾 
            textBox.Select(textBox.Text.Length, 0);
            //滚动到控件光标处 
            textBox.ScrollToCaret();
        }
    
        private void button_m_Click(object sender, EventArgs e)
        {
            if (!(Caps_Lock ^ Shift))
                textBox.Text += "m";
            else
                textBox.Text += "M"; textBox.Focus();
            //设置光标的位置到文本尾 
            textBox.Select(textBox.Text.Length, 0);
            //滚动到控件光标处 
            textBox.ScrollToCaret();
        }
    
        private void button_comma_Click(object sender, EventArgs e)
        {
            if (Shift)
                textBox.Text += "<";
            else
                textBox.Text += ","; textBox.Focus();
            //设置光标的位置到文本尾 
            textBox.Select(textBox.Text.Length, 0);
            //滚动到控件光标处 
            textBox.ScrollToCaret();
        }
    
        private void button_period_Click(object sender, EventArgs e)
        {
            if (Shift)
                textBox.Text += ">";
            else
                textBox.Text += ".";
            textBox.Focus();
            //设置光标的位置到文本尾 
            textBox.Select(textBox.Text.Length, 0);
            //滚动到控件光标处 
            textBox.ScrollToCaret();
        }
    
        private void button_question_Click(object sender, EventArgs e)
        {
            if (Shift)
                textBox.Text += "?";
            else
                textBox.Text += "/";
            textBox.Focus();
            //设置光标的位置到文本尾 
            textBox.Select(textBox.Text.Length, 0);
            //滚动到控件光标处 
            textBox.ScrollToCaret();
        }
    
        private void button_space_Click(object sender, EventArgs e)
        {
            textBox.Text += " ";
            textBox.Focus();
            //设置光标的位置到文本尾 
            textBox.Select(textBox.Text.Length, 0);
            //滚动到控件光标处 
            textBox.ScrollToCaret();
        }
    
        private void button_clear_Click(object sender, EventArgs e)
        {
            textBox.Text = "";
            textBox.Focus();
            //设置光标的位置到文本尾 
            textBox.Select(textBox.Text.Length, 0);
            //滚动到控件光标处 
            textBox.ScrollToCaret();
        }
    
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132
    • 133
    • 134
    • 135
    • 136
    • 137
    • 138
    • 139
    • 140
    • 141
    • 142
    • 143
    • 144
    • 145
    • 146
    • 147
    • 148
    • 149
    • 150
    • 151
    • 152
    • 153
    • 154
    • 155
    • 156
    • 157
    • 158
    • 159
    • 160
    • 161
    • 162
    • 163
    • 164
    • 165
    • 166
    • 167
    • 168
    • 169
    • 170
    • 171
    • 172
    • 173
    • 174
    • 175
    • 176
    • 177
    • 178
    • 179
    • 180
    • 181
    • 182
    • 183
    • 184
    • 185
    • 186
    • 187
    • 188
    • 189
    • 190
    • 191
    • 192
    • 193
    • 194
    • 195
    • 196
    • 197
    • 198
    • 199
    • 200
    • 201
    • 202
    • 203
    • 204
    • 205
    • 206
    • 207
    • 208
    • 209
    • 210
    • 211
    • 212
    • 213
    • 214
    • 215
    • 216
    • 217
    • 218
    • 219
    • 220
    • 221
    • 222
    • 223
    • 224
    • 225
    • 226
    • 227
    • 228
    • 229
    • 230
    • 231
    • 232
    • 233
    • 234
    • 235
    • 236
    • 237
    • 238
    • 239
    • 240
    • 241
    • 242
    • 243
    • 244
    • 245
    • 246
    • 247
    • 248
    • 249
    • 250
    • 251
    • 252
    • 253
    • 254
    • 255
    • 256
    • 257
    • 258
    • 259
    • 260
    • 261
    • 262
    • 263
    • 264
    • 265
    • 266
    • 267
    • 268
    • 269
    • 270
    • 271
    • 272
    • 273
    • 274
    • 275
    • 276
    • 277
    • 278
    • 279
    • 280
    • 281
    • 282
    • 283
    • 284
    • 285
    • 286
    • 287
    • 288
    • 289
    • 290
    • 291
    • 292
    • 293
    • 294
    • 295
    • 296
    • 297
    • 298
    • 299
    • 300
    • 301
    • 302
    • 303
    • 304
    • 305
    • 306
    • 307
    • 308
    • 309
    • 310
    • 311
    • 312
    • 313
    • 314
    • 315
    • 316
    • 317
    • 318
    • 319
    • 320
    • 321
    • 322
    • 323
    • 324
    • 325
    • 326
    • 327
    • 328
    • 329
    • 330
    • 331
    • 332
    • 333
    • 334
    • 335
    • 336
    • 337
    • 338
    • 339
    • 340
    • 341
    • 342
    • 343
    • 344
    • 345
    • 346
    • 347
    • 348
    • 349
    • 350
    • 351
    • 352
    • 353
    • 354
    • 355
    • 356
    • 357
    • 358
    • 359
    • 360
    • 361
    • 362
    • 363
    • 364
    • 365
    • 366
    • 367
    • 368
    • 369
    • 370
    • 371
    • 372
    • 373
    • 374
    • 375
    • 376
    • 377
    • 378
    • 379
    • 380
    • 381
    • 382
    • 383
    • 384
    • 385
    • 386
    • 387
    • 388
    • 389
    • 390
    • 391
    • 392
    • 393
    • 394
    • 395
    • 396
    • 397
    • 398
    • 399
    • 400
    • 401
    • 402
    • 403
    • 404
    • 405
    • 406
    • 407
    • 408
    • 409
    • 410
    • 411
    • 412
    • 413
    • 414
    • 415
    • 416
    • 417
    • 418
    • 419
    • 420
    • 421
    • 422
    • 423
    • 424
    • 425
    • 426
    • 427
    • 428
    • 429
    • 430
    • 431
    • 432
    • 433
    • 434
    • 435
    • 436
    • 437
    • 438
    • 439
    • 440
    • 441
    • 442
    • 443
    • 444
    • 445
    • 446
    • 447
    • 448
    • 449
    • 450
    • 451
    • 452
    • 453
    • 454
    • 455
    • 456
    • 457
    • 458
    • 459
    • 460
    • 461
    • 462
    • 463
    • 464
    • 465
    • 466
    • 467
    • 468
    • 469
    • 470
    • 471
    • 472
    • 473
    • 474
    • 475
    • 476
    • 477
    • 478
    • 479
    • 480
    • 481
    • 482
    • 483
    • 484
    • 485
    • 486
    • 487
    • 488
    • 489
    • 490
    • 491
    • 492
    • 493
    • 494
    • 495
    • 496
    • 497
    • 498
    • 499
    • 500
    • 501
    • 502
    • 503
    • 504
    • 505
    • 506
    • 507
    • 508
    • 509
    • 510
    • 511
    • 512
    • 513
    • 514
    • 515
    • 516
    • 517
    • 518
    • 519
    • 520
    • 521
    • 522
    • 523
    • 524
    • 525
    • 526
    • 527
    • 528
    • 529
    • 530
    • 531
    • 532
    • 533
    • 534
    • 535
    • 536
    • 537
    • 538
    • 539
    • 540
    • 541
    • 542
    • 543
    • 544
    • 545
    • 546
    • 547
    • 548
    • 549
    • 550
    • 551
    • 552
    • 553
    • 554
    • 555
    • 556
    • 557
    • 558
    • 559
    • 560
    • 561
    • 562
    • 563
    • 564
    • 565
    • 566
    • 567
    • 568
    • 569
    • 570
    • 571
    • 572
    • 573
    • 574
    • 575
    • 576
    • 577
    • 578
    • 579
    • 580
    • 581
    • 582
    • 583
    • 584
    • 585
    • 586
    • 587
    • 588
    • 589
    • 590
    • 591
    • 592
    • 593
    • 594
    • 595
    • 596
    • 597
    • 598
    • 599
    • 600
    • 601
    • 602
    • 603
    • 604
    • 605
    • 606
    • 607
    • 608
    • 609
    • 610
    • 611
    • 612
    • 613
    • 614
    • 615
    • 616
    • 617
    • 618
    • 619
    • 620
    • 621
    • 622
    • 623
    • 624
    • 625
    • 626
    • 627
    • 628
    • 629
    • 630
    • 631
    • 632
    • 633
    • 634
    • 635
    • 636
    • 637
    • 638
    • 639
    • 640
    • 641
    • 642
    • 643
    • 644
    • 645
    • 646
    • 647
    • 648
    • 649
    • 650
    • 651
    • 652
    • 653
    • 654
    • 655
    • 656
    • 657
    • 658
    • 659
    • 660
    • 661
    • 662
    • 663
    • 664
    • 665
    • 666
    • 667
    • 668
    • 669
    • 670
    • 671
    • 672
    • 673
    • 674
    • 675
    • 676
    • 677
    • 678
    • 679
    • 680
    • 681
    • 682
    • 683
    • 684
    • 685
    • 686
    • 687
    • 688
    • 689
    • 690
    • 691
    • 692
    • 693
    • 694
    • 695
    • 696
    • 697
    • 698
    • 699
    • 700
    • 701
    • 702
    • 703
    • 704
    • 705
    • 706
    • 707
    • 708
    • 709
    • 710
    • 711
    • 712
    • 713
    • 714
    • 715
    • 716
    • 717
    • 718
    • 719
    • 720
    • 721
    • 722
    • 723
    • 724
    • 725
    • 726
    • 727
    • 728
    • 729
    • 730
    • 731
    • 732
    • 733
    • 734
    • 735
    • 736
    • 737
    • 738
    • 739
    • 740
    • 741
    • 742
    • 743
    • 744
    • 745
    • 746
    • 747
    • 748
    • 749
    • 750
    • 751
    • 752
    • 753
    • 754
    • 755
    • 756
    • 757
    • 758
    • 759
    • 760
    • 761
    • 762
    • 763
    • 764
    • 765
    • 766
    • 767
    • 768
    • 769
    • 770
    • 771
    • 772
    • 773
    • 774
    • 775
    • 776
    • 777
    • 778
    • 779
    • 780
    • 781
    • 782
    • 783
    • 784
    • 785
    • 786
    • 787
    • 788
    • 789
    • 790
    • 791
    • 792
    • 793
    • 794
    • 795
    • 796
    • 797
    • 798
    • 799
    • 800
    • 801
    • 802
    • 803
    • 804
    • 805
    • 806
    • 807
    • 808
    • 809
    • 810
    • 811
    • 812
    • 813
    • 814
    • 815
    • 816
    • 817
    • 818
    • 819
    • 820
    • 821
    • 822
    • 823
    • 824

    }

  • 相关阅读:
    python os.path.abspath()与os.path.realpath()区别
    将目标检测项目移植到linux上出现OSERROR
    开发 pgadmin4 遇到后后端无法切换目标数据库的问题
    ORB-SLAM2实时稠密地图,解决运行报段错误(核心已转储)运行数据集时出现段错误,出现可视化界面后闪退(添加实时彩色点云地图+保存点云地图)
    机器学习笔记之指数族分布——最大熵原理与softmax激活函数的关系
    (二)Python类型总结
    电脑打开图片比例太大怎么调?这个方法又快又好用
    Node.js中的child_process模块的作用
    Unity 打印安卓apk报错的日志
    独家 | 机器学习前沿:为什么上下文是一切(附链接)
  • 原文地址:https://blog.csdn.net/weixin_41883890/article/details/126052226