我想要清除表單上的文本字段後,再次對焦。這裏是我的表單代碼中,我想清楚了名爲user_textbox
和pwd_textbox
如何在返回表單時清除文本字段
namespace RDASMS
{
public partial class Login : Form
{
public Login()
{
InitializeComponent();
user_textbox.Clear();
pwd_textbox.Clear();
}
private void register_Click(object sender, EventArgs e)
{
Registration newuser = new Registration();
newuser.Show();
this.Hide();
}
private void submit_login_Click(object sender, EventArgs e)
{
int checkuser = string.CompareOrdinal(user_textbox.Text, "Admin");
if (checkuser == 0)
{
int checkpwd = string.CompareOrdinal(pwd_textbox.Text, "rnsit123");
if (checkpwd == 0)
{
Admin newuser = new Admin();
newuser.RefToLogin = this;
newuser.Show();
this.Hide();
}
else
MessageBox.Show("Invalid Password");
}
else
MessageBox.Show("Invalid Username");
}
}
}
[你有什麼嘗試?](http://whathaveyoutried.com) - 你遇到了什麼問題? – Blachshma 2013-03-18 12:35:39
你如何回到主表格?您只顯示隱藏主要代碼並將其他表單帶到前臺的代碼。 – 2013-03-18 12:41:04
好吧,沒有必要在構造函數中清除它們。在'InitializeComponent()'方法中,文本框是_created_。你有沒有看過[當表單獲得焦點並且觸發了什麼潛在的事件](http://msdn.microsoft.com/en-us/library/system.windows.forms.control.gotfocus.aspx)? – Default 2013-03-18 12:47:44