您当前的位置: 首页 >  c#

txwtech

暂无认证

  • 3浏览

    0关注

    813博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

c#启动时窗口默认光标聚焦位置设置

txwtech 发布时间:2019-05-29 17:40:08 ,浏览量:3

选中该文本框,右击属性,里的tabIndex设为0,焦点就默认在这个文本框里了。

Formload里面添加:

比如编辑框的名字:textBox_password

this.BeginInvoke((MethodInvoker)delegate {                 textBox_password.Focus();             });

        private void button_Search_Click(object sender, EventArgs e)
        {
            string str1;
            // strDate= dateTimePicker1.ToString("yyyyMMdd");
            str1 = dateTimePicker1.Value.ToString("yyyyMMdd");
            str1 += ".txt";
            textBox1.Text = "";
            try
            {
                string[] ReadData = File.ReadAllLines(Application.StartupPath + "\\" + str1, Encoding.UTF8);
                // textBox1.Text = ReadData[0];

                for (int i = 0; i < ReadData.Length; i++)
                {
                    textBox1.Text += ReadData[i];
                    textBox1.Text += "\r\n";
                }
              //  textBox1.Select(0, 0);//光标停留的位置
              //  textBox1.Focus();//可以显示光标
               // textBox1.SelectionStart = textBox1.Text.Length;
                textBox1.Select(textBox1.Text.Length, 0);//光标停留在最后末尾
            }
            catch (Exception ex)
            {
                MessageBox.Show("所选日期无报警记录");
            }

           
        }

关注
打赏
1665060526
查看更多评论
立即登录/注册

微信扫码登录

0.0415s