c#点击按钮-更新编辑控件-编辑控件执行回车keypress事件

参考

https://tiegen.blog.csdn.net/article/details/104990098?spm=1001.2101.3001.6650.1&utm_medium=distribute.pc_relevant.none-task-blog-2~default~CTRLIST~Rate-1.pc_relevant_antiscanv2&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2~default~CTRLIST~Rate-1.pc_relevant_antiscanv2&utm_relevant_index=2

  private void textBox_test1_KeyPress(object sender, KeyPressEventArgs e)
        {
            if(e.KeyChar==13)
            {
                MessageBox.Show("keyPressed.....");
            }
            
        }

        private void button2_Click(object sender, EventArgs e)
        {

            // this.button1_Click(sender, e);//按钮点击事件函数
            // button2.PerformClick();
            textBox_test1.Text = "";
            // textBox_test1.KeyPress(this, KeyPressEventHandler e);
            textBox_test1.Text = "abcdeff\r";



        }

        private void textBox_test1_TextChanged(object sender, EventArgs e)
        {
            if (System.Text.RegularExpressions.Regex.IsMatch(textBox_test1.Text, @".*\r$"))
            {

                KeyPressEventArgs e1 = new KeyPressEventArgs('\r');
                textBox_test1_KeyPress(this.textBox_test1, e1);
            }

        }

 

posted @ 2022-04-01 13:12  txwtech  阅读(238)  评论(0编辑  收藏  举报