Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.Drawing;
- namespace MyForm
- {
- class Login:Form
- {
- private Button btLogin; //private because it's an attribute to the class. an object so no need for properties
- private TextBox username;
- private TextBox password;
- private Label un;
- private Label pw;
- public Login()
- {
- InitializeComponents();
- }
- public void InitializeComponents()
- {
- this.Text = "Login Form";
- this.BackColor = Color.Lavender;
- this.ForeColor = Color.Black;
- this.Size = new Size(250, 300);
- this.StartPosition = FormStartPosition.CenterScreen;
- btLogin = new Button();
- btLogin.Text = "Login";
- btLogin.Location = new Point(70,150);
- btLogin.Click += btLogin_Click;
- un = new Label();
- un.Text = "Username";
- un.Location = new Point(20,80);
- username = new TextBox();
- username.Text = "";
- username.Location = new Point(80,80);
- pw = new Label();
- pw.Text = "Password";
- pw.Location = new Point(20,110);
- password = new TextBox();
- password.Text = "";
- password.PasswordChar = '*';
- password.MaxLength = 10;
- password.Location = new Point(80,110);
- this.Controls.Add(username);
- this.Controls.Add(password);
- this.Controls.Add(btLogin);
- this.Controls.Add(un);
- this.Controls.Add(pw);
- }
- public void btLogin_Click(object sender, EventArgs e)
- {
- DialogResult dr = MessageBox.Show("Enter Main Form?", "Login", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk);
- if (dr == DialogResult.Yes)
- {
- MainForms mf = new MainForms(username.Text); //this is just an instance
- mf.Show();
- this.Hide();
- }
- else
- MessageBox.Show("Goodbye.");
- }
- }
- class MainForms:Form
- {
- public MainForms(string username)
- {
- this.Text = username;
- this.FormClosing += ThisOnFormClosing;
- }
- public void ThisOnFormClosing(object sender, FormClosingEventArgs e)
- {
- Login myLogin = new Login();
- myLogin.Show();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement