943,708 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Marked Solved
  • Views: 3050
  • C# RSS
You are currently viewing page 1 of this multi-page discussion thread
Jan 18th, 2008
0

My login UI

Expand Post »
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() );
    }
/*-----------------------------------------------------------------------------------------*/   
      
}
Similar Threads
Reputation Points: 256
Solved Threads: 72
Nearly a Posting Virtuoso
majestic0110 is offline Offline
1,306 posts
since Oct 2007
Jan 19th, 2008
0

Re: My login UI

C# Syntax (Toggle Plain Text)
  1. if(txtUser.Text == "MJ12" && txtPass.Text == "Roswell1947")
  2. {
  3. //need help here!
  4. }

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)
  1. if(txtUser.Text == "MJ12" && txtPass.Text == "Roswell1947")
  2. {
  3. // Create instance of the mainForm class
  4. Form nextForm = new MainForm();
  5. }

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.
Reputation Points: 21
Solved Threads: 10
Junior Poster
Paul.Esson is offline Offline
181 posts
since Feb 2005
Jan 19th, 2008
0

Re: My login UI

Many thanks for your reply, it is helpful but the issue is that I have already have anothr class that displays a form (class2) which I want to be opened when a correct username/password is entered. Any ideas on that would be helpful. Thanks
Reputation Points: 256
Solved Threads: 72
Nearly a Posting Virtuoso
majestic0110 is offline Offline
1,306 posts
since Oct 2007
Jan 19th, 2008
0

Re: My login UI

C# Syntax (Toggle Plain Text)
  1. if(txtUser.Text == "MJ12" && txtPass.Text == "Roswell1947")
  2. {
  3. // Create instance of the mainForm class
  4. Form nextForm = new Class2();
  5. // We may need to make it visable
  6. nextForm.Visible=true;
  7. }

I think that should work, But don't have Windows.Forms on this computer to play around with, so am abit uncertain
Reputation Points: 21
Solved Threads: 10
Junior Poster
Paul.Esson is offline Offline
181 posts
since Feb 2005
Jan 19th, 2008
0

Re: My login UI

lol thanks for your help again, unfortunately I had tried that befre posting and I get a compilation error "the type or namespace 'class2' could not be found. (are you missing a using directive or assembly reference?)(CS0246).
Any thoughts on that ? thanks again for your help
Reputation Points: 256
Solved Threads: 72
Nearly a Posting Virtuoso
majestic0110 is offline Offline
1,306 posts
since Oct 2007
Jan 19th, 2008
1

Re: My login UI

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

C# Syntax (Toggle Plain Text)
  1. public class UserLogin : Form

your second form says

C# Syntax (Toggle Plain Text)
  1. 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)
  1. if(txtUser.Text == "MJ12" && txtPass.Text == "Roswell1947")
  2. {
  3. // Create instance of the mainForm class
  4. Form nextForm = new class2();
  5. // We may need to make it visable
  6. nextForm.Visible=true;
  7. }
Reputation Points: 21
Solved Threads: 10
Junior Poster
Paul.Esson is offline Offline
181 posts
since Feb 2005
Jan 19th, 2008
0

Re: My login UI

thanks pal, would you believe it I made a caps error on class declaration! i.e. it was class2 not Class2! THanks a million! that really is an annoying little error I spent ages trying to figure that out! working good now
Reputation Points: 256
Solved Threads: 72
Nearly a Posting Virtuoso
majestic0110 is offline Offline
1,306 posts
since Oct 2007
Jan 19th, 2008
0

Re: My login UI

I'm working on the same thing only i want to make my login thing to work through a data base.... Mind helping me?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
lAZLf is offline Offline
2 posts
since Jan 2008
Jan 19th, 2008
0

Re: My login UI

How are you creating the database? SQL? XML?
Reputation Points: 256
Solved Threads: 72
Nearly a Posting Virtuoso
majestic0110 is offline Offline
1,306 posts
since Oct 2007
Jan 19th, 2008
0

Re: My login UI

Sql....
Reputation Points: 10
Solved Threads: 0
Newbie Poster
lAZLf is offline Offline
2 posts
since Jan 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: Read Between Certain Tags
Next Thread in C# Forum Timeline: How to Block Save button in FileDownload dialog box ?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC