My login UI

Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Oct 2007
Posts: 1,296
Reputation: majestic0110 has a spectacular aura about majestic0110 has a spectacular aura about majestic0110 has a spectacular aura about 
Solved Threads: 67
majestic0110's Avatar
majestic0110 majestic0110 is offline Offline
Nearly a Posting Virtuoso

My login UI

 
0
  #1
Jan 18th, 2008
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() );
    }
/*-----------------------------------------------------------------------------------------*/   
      
}
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 181
Reputation: Paul.Esson is an unknown quantity at this point 
Solved Threads: 10
Paul.Esson's Avatar
Paul.Esson Paul.Esson is offline Offline
Junior Poster

Re: My login UI

 
0
  #2
Jan 19th, 2008
  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

  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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 1,296
Reputation: majestic0110 has a spectacular aura about majestic0110 has a spectacular aura about majestic0110 has a spectacular aura about 
Solved Threads: 67
majestic0110's Avatar
majestic0110 majestic0110 is offline Offline
Nearly a Posting Virtuoso

Re: My login UI

 
0
  #3
Jan 19th, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 181
Reputation: Paul.Esson is an unknown quantity at this point 
Solved Threads: 10
Paul.Esson's Avatar
Paul.Esson Paul.Esson is offline Offline
Junior Poster

Re: My login UI

 
0
  #4
Jan 19th, 2008
  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
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 1,296
Reputation: majestic0110 has a spectacular aura about majestic0110 has a spectacular aura about majestic0110 has a spectacular aura about 
Solved Threads: 67
majestic0110's Avatar
majestic0110 majestic0110 is offline Offline
Nearly a Posting Virtuoso

Re: My login UI

 
0
  #5
Jan 19th, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 181
Reputation: Paul.Esson is an unknown quantity at this point 
Solved Threads: 10
Paul.Esson's Avatar
Paul.Esson Paul.Esson is offline Offline
Junior Poster

Re: My login UI

 
1
  #6
Jan 19th, 2008
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

  1. public class UserLogin : Form

your second form says

  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

  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. }
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 1,296
Reputation: majestic0110 has a spectacular aura about majestic0110 has a spectacular aura about majestic0110 has a spectacular aura about 
Solved Threads: 67
majestic0110's Avatar
majestic0110 majestic0110 is offline Offline
Nearly a Posting Virtuoso

Re: My login UI

 
0
  #7
Jan 19th, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 2
Reputation: lAZLf is an unknown quantity at this point 
Solved Threads: 0
lAZLf lAZLf is offline Offline
Newbie Poster

Re: My login UI

 
0
  #8
Jan 19th, 2008
I'm working on the same thing only i want to make my login thing to work through a data base.... Mind helping me?
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 1,296
Reputation: majestic0110 has a spectacular aura about majestic0110 has a spectacular aura about majestic0110 has a spectacular aura about 
Solved Threads: 67
majestic0110's Avatar
majestic0110 majestic0110 is offline Offline
Nearly a Posting Virtuoso

Re: My login UI

 
0
  #9
Jan 19th, 2008
How are you creating the database? SQL? XML?
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 2
Reputation: lAZLf is an unknown quantity at this point 
Solved Threads: 0
lAZLf lAZLf is offline Offline
Newbie Poster

Re: My login UI

 
0
  #10
Jan 19th, 2008
Sql....
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C# Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC