| | |
My login UI
Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved |
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!
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() );
}
/*-----------------------------------------------------------------------------------------*/
} C# Syntax (Toggle Plain Text)
if(txtUser.Text == "MJ12" && txtPass.Text == "Roswell1947") { //need help here! }
I am guessing that you want to create another windows forum at this point.
so you may want to do something like this
C# Syntax (Toggle Plain Text)
if(txtUser.Text == "MJ12" && txtPass.Text == "Roswell1947") { // Create instance of the mainForm class Form nextForm = new MainForm(); }
You would have to create a new form and in the case name it MainForm, this will then load the next form when they enter the correct sername and password.
Anyhow good luck and I hope this helps you.
C# Syntax (Toggle Plain Text)
if(txtUser.Text == "MJ12" && txtPass.Text == "Roswell1947") { // Create instance of the mainForm class Form nextForm = new Class2(); // We may need to make it visable nextForm.Visible=true; }
I think that should work, But don't have Windows.Forms on this computer to play around with, so am abit uncertain
If your second class has been defined as class2 and is accessible within your current form ( in the same project and within the same namespace ) it should work. That error suggests that it is unable to find the class named class2,
Just make certain that where this one says
your second form says
note it is caps sensitive and I did say to use Class2 so if you have named your class 'class2' insted of 'Class2' you will have to write
Just make certain that where this one says
C# Syntax (Toggle Plain Text)
public class UserLogin : Form
your second form says
C# Syntax (Toggle Plain Text)
public class Class2 : Form
note it is caps sensitive and I did say to use Class2 so if you have named your class 'class2' insted of 'Class2' you will have to write
C# Syntax (Toggle Plain Text)
if(txtUser.Text == "MJ12" && txtPass.Text == "Roswell1947") { // Create instance of the mainForm class Form nextForm = new class2(); // We may need to make it visable nextForm.Visible=true; }
![]() |
Similar Threads
- Windows XP slow login (Windows NT / 2000 / XP)
- network login problem (Windows NT / 2000 / XP)
- can't get past xp login (Windows NT / 2000 / XP)
- XP anf Novell Client Dual Login (Novell)
- Cannot Login to Mac (OS X)
- login screen config (Window and Desktop Managers)
Other Threads in the C# Forum
- Previous Thread: Read Between Certain Tags
- Next Thread: How to Block Save button in FileDownload dialog box ?
| Thread Tools | Search this Thread |
.net access ado.net algorithm array barchart bitmap box broadcast buttons c# chat check checkbox client color combobox control conversion csharp custom database datagrid datagridview dataset datetime degrees development draganddrop drawing encryption enum event excel file files form format forms function gdi+ httpwebrequest image index input install interface java label list listbox listener mandelbrot math mouseclick mysql networking object operator path photoshop picturebox pixelinversion post prime programming radians regex remote remoting richtextbox save saving serialization server sleep socket sql statistics stream string table tcp tcpclientchannel text textbox thread time timer treeview update usercontrol validation view visualstudio webbrowser windows winforms wpf xml






