设置焦点不起作用的问题
issue with setting focus not working
我有一个屏幕,用户可以在其中的文本框中输入位置名称。然后单击一个按钮打开一个包含三个文本框 Firstname、lastname 和 PW 的组框。当用户单击按钮以使组框可见(在主窗体上)时,我试图将焦点设置到名字文本框。但它不会设置焦点 (txtbxnameFirst.focus();)
要求
我理解了以下内容:
用户将文本写入 locationTextBox
并单击按钮 locationSaveButton
点击按钮后,GroupBoxControl
应设置为可见,firstNameTextBox
应获得焦点
代码
输入位置后点击的按钮 locationButton
有一个带有此代码的点击事件
private void locationButton_Click(object sender, EventArgs e)
{
// get value from textbox location
string location = locationTextBox.Text;
// make the groupBox visible
groupBox1.Visible = true;
// set the focus to the textbox for the firstname
firstNameTextBox.Focus();
}
具有 windows 表单的简单演示
这是单击按钮之前应用程序的外观
单击后,groubBox 设置为可见,其他 TextBox 可见,焦点设置为 firstNameTextBox
我有一个屏幕,用户可以在其中的文本框中输入位置名称。然后单击一个按钮打开一个包含三个文本框 Firstname、lastname 和 PW 的组框。当用户单击按钮以使组框可见(在主窗体上)时,我试图将焦点设置到名字文本框。但它不会设置焦点 (txtbxnameFirst.focus();)
要求
我理解了以下内容:
用户将文本写入
locationTextBox
并单击按钮locationSaveButton
点击按钮后,
GroupBoxControl
应设置为可见,firstNameTextBox
应获得焦点
代码
输入位置后点击的按钮 locationButton
有一个带有此代码的点击事件
private void locationButton_Click(object sender, EventArgs e)
{
// get value from textbox location
string location = locationTextBox.Text;
// make the groupBox visible
groupBox1.Visible = true;
// set the focus to the textbox for the firstname
firstNameTextBox.Focus();
}
具有 windows 表单的简单演示
这是单击按钮之前应用程序的外观
单击后,groubBox 设置为可见,其他 TextBox 可见,焦点设置为 firstNameTextBox