Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Windows.Forms;
- using System.Drawing;
- using System.IO;
- namespace MyForm
- {
- public class Register : Form
- {
- private Button btCancel;
- private Button btContinue;
- private TextBox username;
- private TextBox password;
- private Label uname;
- private Label passw;
- private Label accntype;
- private CheckBox chPass;
- private ComboBox cbType;
- public Register()
- {
- InitializeComponents();
- }
- public void InitializeComponents()
- {
- this.Text = "Register";
- this.BackColor = Color.Lavender;
- this.ForeColor = Color.Black;
- this.Size = new Size(250, 300);
- this.StartPosition = FormStartPosition.CenterScreen;
- btContinue = new Button();
- btContinue.Location = new Point(40, 220);
- btContinue.Text = "Continue";
- btContinue.Click += btContinue_Click;
- btCancel = new Button();
- btCancel.Location = new Point(120, 220);
- btCancel.Text = "Cancel";
- btCancel.Click += btCancel_Click;
- username = new TextBox();
- username.Text = "";
- username.MaxLength = 10;
- username.Location = new Point(80, 30);
- password = new TextBox();
- password.Text = "";
- password.UseSystemPasswordChar = true;
- password.Location = new Point(80, 60);
- uname = new Label();
- uname.Text = "Username";
- uname.Location = new Point(20, 30);
- passw = new Label();
- passw.Text = "Password";
- passw.Location = new Point(20, 60);
- accntype = new Label();
- accntype.Text = "Account";
- accntype.Location = new Point(20, 110);
- chPass = new CheckBox();
- chPass.Location = new Point(80, 78);
- chPass.TabIndex = 8;
- chPass.Text = "Show Password";
- chPass.UseVisualStyleBackColor = true;
- chPass.CheckedChanged += new System.EventHandler(chPass_CheckedChanged);
- cbType = new ComboBox();
- cbType.Location = new Point(80, 110);
- cbType.Items.AddRange(new object[] { "Type One", "Type Two" });
- this.Controls.Add(username);
- this.Controls.Add(password);
- this.Controls.Add(uname);
- this.Controls.Add(passw);
- this.Controls.Add(chPass);
- this.Controls.Add(cbType);
- this.Controls.Add(accntype);
- this.Controls.Add(btContinue);
- this.Controls.Add(btCancel);
- }
- public void btContinue_Click(object sender, EventArgs e)
- {
- string path = String.Concat("", username.Text, ".txt");
- if (File.Exists(path))
- {
- MessageBox.Show("Username is already taken.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
- return;
- }
- else if (username.Text == "" || password.Text == "" || cbType.Text == "")
- {
- MessageBox.Show("Please fill in empty blanks.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
- return;
- }
- using (StreamWriter sw = new StreamWriter(path))
- {
- sw.WriteLine(password.Text);
- sw.WriteLine(cbType.Text);
- }
- this.Hide();
- Login log = new Login();
- log.Show();
- }
- public void btCancel_Click(object sender, EventArgs e)
- {
- Index ind = new Index();
- ind.Show();
- this.Hide();
- }
- private void chPass_CheckedChanged(object sender, EventArgs e)
- {
- if (chPass.CheckState == CheckState.Checked)
- password.UseSystemPasswordChar = false;
- else
- password.UseSystemPasswordChar = true;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement