Hi all, just would like to ask some help as to how I would go about modifying this code I created to do the following:
1 - need user input (in password field) to be echoed back as *******.
2 - need the class to open a new class (lets call that class class2 for now) upon entry of correct credentials.Many thanks!
/* Phil
*
*/
using System;
using System.Windows.Forms;
using System.Drawing;
public class UserLogin : Form
{
private Button btnOk;
private Button btnCancel;
private Label lblUser;
private Label lblPass;
private Label lblInst;
private TextBox txtUser;
private TextBox txtPass;
/*-----------------------------------------------------------------------------------------*/
public UserLogin()
{
InitializeComponent();
}
/*-----------------------------------------------------------------------------------------*/
private void InitializeComponent()
{
this.FormBorderStyle = FormBorderStyle.Fixed3D;
this.Size = new System.Drawing.Size(300, 300);
this.Text = "User Login Screen";
this.MinimizeBox = true;
this.MaximizeBox = false;
this.HelpButton = false;
this.ControlBox = true;
this.StartPosition = FormStartPosition.CenterScreen;
// Instantiate the controls...
lblInst = new Label();
lblUser = new Label();
lblPass = new Label();
txtUser = new TextBox();
txtPass = new TextBox();
btnOk = new Button();
btnCancel = new Button();
// Set properties
lblInst.AutoSize = true;
lblInst.Text = "Please supply your credentials:";
lblInst.Location = new Point(20, 20);
lblUser.AutoSize = true;
lblUser.Text = "Username:";
lblUser.Location = new Point(20, 50);
lblPass.AutoSize = true;
lblPass.Text = "Password:";
lblPass.Location = new Point(20, 80);
txtUser.Width = 100;
txtUser.Location = new Point(140, 50);
txtPass.Width = 100;
txtPass.Location = new Point(140, 80);
btnOk.Text = "OK";
btnOk.BackColor = Color.LightGray;
btnOk.Location = new Point(50, 200);
btnCancel.Text = "Cancel";
btnCancel.BackColor = Color.LightGray;
btnCancel.Location = new Point(150, 200);
this.Controls.Add(lblInst);
this.Controls.Add(lblUser); // Add label to form
this.Controls.Add(lblPass);
this.Controls.Add(txtUser); // add text box to form
this.Controls.Add(txtPass);
this.Controls.Add(btnOk); // Add button to form
this.Controls.Add(btnCancel);
// Event handlers
btnOk.Click += new System.EventHandler(this.btnOk_Click);
btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
}
/*-----------------------------------------------------------------------------------------*/
protected void btnOk_Click( object sender, System.EventArgs e)
{
if(txtUser.Text == "")
{
MessageBox.Show("You must enter a Username.", "Name Entry Error",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
if(txtUser.Text == "MJ12" && txtPass.Text == "Roswell1947")
{
//need help here!
}
if(txtPass.Text == "")
{
MessageBox.Show("You must enter a Password.", "Password Entry Error",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
else
{
// Code to act on the data entered would go here.
}
}
/*-----------------------------------------------------------------------------------------*/
protected void btnCancel_Click( object sender, System.EventArgs e)
{
Application.Exit();
}
/*-----------------------------------------------------------------------------------------*/
public static void Main( string[] args )
{
Application.Run( new UserLogin() );
}
/*-----------------------------------------------------------------------------------------*/
}