Advertisement
gelatofu

Prac_Login.cs

Mar 20th, 2017
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.62 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows.Forms;
  7. using System.Drawing;
  8.  
  9. namespace MyForm
  10. {
  11.     class Login:Form
  12.     {
  13.         private Button btLogin; //private because it's an attribute to the class. an object so no need for properties
  14.         private TextBox username;
  15.         private TextBox password;
  16.         private Label un;
  17.         private Label pw;
  18.  
  19.  
  20.         public Login()
  21.         {
  22.             InitializeComponents();
  23.         }
  24.  
  25.         public void InitializeComponents()
  26.         {
  27.             this.Text = "Login Form";
  28.             this.BackColor = Color.Lavender;
  29.             this.ForeColor = Color.Black;
  30.             this.Size = new Size(250, 300);
  31.             this.StartPosition = FormStartPosition.CenterScreen;
  32.  
  33.  
  34.             btLogin = new Button();
  35.             btLogin.Text = "Login";
  36.             btLogin.Location = new Point(70,150);
  37.             btLogin.Click += btLogin_Click;
  38.  
  39.             un = new Label();
  40.             un.Text = "Username";
  41.             un.Location = new Point(20,80);
  42.  
  43.             username = new TextBox();
  44.             username.Text = "";
  45.             username.Location = new Point(80,80);
  46.  
  47.             pw = new Label();
  48.             pw.Text = "Password";
  49.             pw.Location = new Point(20,110);
  50.  
  51.             password = new TextBox();
  52.             password.Text = "";
  53.             password.PasswordChar = '*';
  54.             password.MaxLength = 10;
  55.             password.Location = new Point(80,110);
  56.  
  57.             this.Controls.Add(username);
  58.             this.Controls.Add(password);
  59.             this.Controls.Add(btLogin);
  60.             this.Controls.Add(un);
  61.             this.Controls.Add(pw);
  62.         }
  63.  
  64.         public void btLogin_Click(object sender, EventArgs e)
  65.         {
  66.             DialogResult dr = MessageBox.Show("Enter Main Form?", "Login", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk);
  67.             if (dr == DialogResult.Yes)
  68.             {
  69.                 MainForms mf = new MainForms(username.Text); //this is just an instance
  70.                 mf.Show();
  71.                 this.Hide();
  72.                
  73.             }
  74.             else
  75.                 MessageBox.Show("Goodbye.");
  76.         }
  77.     }
  78.  
  79.     class MainForms:Form
  80.     {
  81.         public MainForms(string username)
  82.         {
  83.           this.Text = username;
  84.           this.FormClosing += ThisOnFormClosing;
  85.         }
  86.  
  87.         public void ThisOnFormClosing(object sender, FormClosingEventArgs e)
  88.         {
  89.             Login myLogin = new Login();
  90.             myLogin.Show();
  91.         }
  92.     }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement