小编Nat*_* E.的帖子

C#设置焦点在文本框上

我试图设置"txtMiles"文本框以便在以下情况下聚焦:(1)单击清除按钮时窗体打开(2)

我试过使用txtMiles.Focus(); 但它似乎对我不起作用.

*************在本表格上使用的代码*****************************

        private void btnConvert_Click(object sender, EventArgs e)
        {
            //assigns variable in memory.
            double txtMile = 0;
            double Results;

            try
            {
                // here is where the math happens.
                txtMile = double.Parse(txtMiles.Text);
                Results = txtMile * CONVERSION;
                lblResults.Text = Results.ToString("n2");
                txtMiles.Focus();
            }
                // if the user enters an incorrect value this test will alert them of such.
            catch
            {
                //MessageBox.Show (ex.ToString());
                MessageBox.Show("You entered an incorrect value");
                txtMiles.Focus();
            }
        }

        private void btnClear_Click(object sender, EventArgs e)
        {
            //This empties all …
Run Code Online (Sandbox Code Playgroud)

c# controls textbox focus

2
推荐指数
1
解决办法
1万
查看次数

标签 统计

c# ×1

controls ×1

focus ×1

textbox ×1