Advertisement
gelatofu

LabExer5_Register.cs

Mar 29th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.06 KB | None | 0 0
  1. using System;
  2. using System.Windows.Forms;
  3. using System.Drawing;
  4. using System.IO;
  5.  
  6. namespace MyForm
  7. {
  8.     public class Register : Form
  9.     {
  10.         private Button btCancel;
  11.         private Button btContinue;
  12.         private TextBox username;
  13.         private TextBox password;
  14.         private Label uname;
  15.         private Label passw;
  16.         private Label accntype;
  17.         private CheckBox chPass;
  18.         private ComboBox cbType;
  19.  
  20.         public Register()
  21.         {
  22.             InitializeComponents();
  23.         }
  24.  
  25.         public void InitializeComponents()
  26.         {
  27.             this.Text = "Register";
  28.             this.BackColor = Color.Lavender;
  29.             this.ForeColor = Color.Black;
  30.             this.Size = new Size(250, 300);
  31.             this.StartPosition = FormStartPosition.CenterScreen;
  32.  
  33.             btContinue = new Button();
  34.             btContinue.Location = new Point(40, 220);
  35.             btContinue.Text = "Continue";
  36.             btContinue.Click += btContinue_Click;
  37.  
  38.             btCancel = new Button();
  39.             btCancel.Location = new Point(120, 220);
  40.             btCancel.Text = "Cancel";
  41.             btCancel.Click += btCancel_Click;
  42.  
  43.             username = new TextBox();
  44.             username.Text = "";
  45.             username.MaxLength = 10;
  46.             username.Location = new Point(80, 30);
  47.  
  48.             password = new TextBox();
  49.             password.Text = "";
  50.             password.UseSystemPasswordChar = true;
  51.             password.Location = new Point(80, 60);
  52.  
  53.             uname = new Label();
  54.             uname.Text = "Username";
  55.             uname.Location = new Point(20, 30);
  56.  
  57.             passw = new Label();
  58.             passw.Text = "Password";
  59.             passw.Location = new Point(20, 60);
  60.  
  61.             accntype = new Label();
  62.             accntype.Text = "Account";
  63.             accntype.Location = new Point(20, 110);
  64.  
  65.             chPass = new CheckBox();
  66.             chPass.Location = new Point(80, 78);
  67.             chPass.TabIndex = 8;
  68.             chPass.Text = "Show Password";
  69.             chPass.UseVisualStyleBackColor = true;
  70.             chPass.CheckedChanged += new System.EventHandler(chPass_CheckedChanged);
  71.  
  72.             cbType = new ComboBox();
  73.             cbType.Location = new Point(80, 110);
  74.             cbType.Items.AddRange(new object[] { "Type One", "Type Two" });
  75.  
  76.  
  77.             this.Controls.Add(username);
  78.             this.Controls.Add(password);
  79.             this.Controls.Add(uname);
  80.             this.Controls.Add(passw);
  81.             this.Controls.Add(chPass);
  82.             this.Controls.Add(cbType);
  83.             this.Controls.Add(accntype);
  84.             this.Controls.Add(btContinue);
  85.             this.Controls.Add(btCancel);
  86.         }
  87.  
  88.         public void btContinue_Click(object sender, EventArgs e)
  89.         {
  90.             string path = String.Concat("", username.Text, ".txt");
  91.             if (File.Exists(path))
  92.             {
  93.                 MessageBox.Show("Username is already taken.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
  94.                 return;
  95.             }
  96.             else if (username.Text == "" || password.Text == "" || cbType.Text == "")
  97.             {
  98.                 MessageBox.Show("Please fill in empty blanks.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
  99.                 return;
  100.             }
  101.  
  102.             using (StreamWriter sw = new StreamWriter(path))
  103.             {
  104.                 sw.WriteLine(password.Text);
  105.                 sw.WriteLine(cbType.Text);
  106.             }
  107.             this.Hide();
  108.             Login log = new Login();
  109.             log.Show();
  110.         }
  111.  
  112.         public void btCancel_Click(object sender, EventArgs e)
  113.         {
  114.             Index ind = new Index();
  115.             ind.Show();
  116.             this.Hide();
  117.         }
  118.  
  119.         private void chPass_CheckedChanged(object sender, EventArgs e)
  120.         {
  121.             if (chPass.CheckState == CheckState.Checked)
  122.                 password.UseSystemPasswordChar = false;
  123.             else
  124.                 password.UseSystemPasswordChar = true;
  125.         }
  126.     }
  127. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement