I am having a problem with this code
The controls themselves are declared and added to the tab, but how come the compiler says that they do not exist?
Code:
private void loginButton_Click(object sender, System.EventArgs e)
{
if (userTB.Text == "")
{
MessageBox.Show("You have not entered a username");
return;
}
else if (userPass.Text == "")
{
MessageBox.Show("You have not entered a password");
return;
}
MessageBox.Show("You have been logged in!");
}
Code:
private void FirstLogin()
{
TabPage loginTab = new TabPage("Login");
loginTab.BackColor = SystemColors.Control;
tabControl1.TabPages.Add(loginTab); // add the tab
Label loginLabel = new Label();
loginLabel.Text = "You are required to log in before you can access the system.";
loginLabel.AutoSize = true;
Label userName = new Label();
userName.Text = "Username: ";
userName.AutoSize = true;
userName.Location = new System.Drawing.Point(0, 30);
TextBox userTB = new TextBox();
userTB.Location = new System.Drawing.Point(61, 28);
Label password = new Label();
password.Text = "Password: ";
password.AutoSize = true;
password.Location = new System.Drawing.Point(0, 60);
TextBox userPass = new TextBox();
userPass.Location = new System.Drawing.Point(61, 58);
userPass.PasswordChar = '*';
Button loginButton = new Button();
loginButton.Location = new System.Drawing.Point(0, 90);
loginButton.Text = "Login";
loginButton.Click += new System.EventHandler(loginButton_Click);
loginTab.Controls.Add(loginLabel);
loginTab.Controls.Add(userName);
loginTab.Controls.Add(userTB);
loginTab.Controls.Add(userPass);
loginTab.Controls.Add(password);
loginTab.Controls.Add(loginButton);
}
Comment