Guest User

Form Sign In Dialog

a guest
Apr 24th, 2013
454
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 8.23 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9.  
  10. namespace XNASignIn
  11. {
  12.     public partial class XNASignIn : Form
  13.     {
  14.         private bool ResultSet = false;
  15.  
  16.         public XNASignIn()
  17.         {
  18.             InitializeComponent();
  19.         }
  20.  
  21.         protected override void OnShown(EventArgs e)
  22.         {
  23.             ResultSet = false;
  24.             base.OnShown(e);
  25.         }
  26.  
  27.         protected override void OnClosed(EventArgs e)
  28.         {
  29.             if (!ResultSet)
  30.             {
  31.                 this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
  32.             }
  33.  
  34.             base.OnClosed(e);
  35.         }
  36.  
  37.         private void btnOK_Click(object sender, EventArgs e)
  38.         {
  39.             ResultSet = true;
  40.  
  41.             // check user here
  42.             // an example that's very simple:
  43.             if (this.inputUsername.Text == "user" && this.inputPassword.Text == "password")
  44.             {
  45.                 this.DialogResult = System.Windows.Forms.DialogResult.OK;
  46.             }
  47.             else
  48.             {
  49.                 this.DialogResult = System.Windows.Forms.DialogResult.Abort;
  50.             }
  51.         }
  52.  
  53.         private void btnCancel_Click(object sender, EventArgs e)
  54.         {
  55.             ResultSet = true;
  56.             this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
  57.         }
  58.  
  59.         private string username = string.Empty;
  60.         public string Username { get { return username; } set { username = value; }  }
  61.  
  62.         private string password = string.Empty;
  63.         public string Password { get { return password; } set { password = value; }  }
  64.  
  65.         private void InitializeComponent()
  66.         {
  67.             this.panelButtons = new System.Windows.Forms.Panel();
  68.             this.btnOK = new System.Windows.Forms.Button();
  69.             this.btnCancel = new System.Windows.Forms.Button();
  70.             this.panel1 = new System.Windows.Forms.Panel();
  71.             this.inputPassword = new System.Windows.Forms.TextBox();
  72.             this.label2 = new System.Windows.Forms.Label();
  73.             this.inputUsername = new System.Windows.Forms.TextBox();
  74.             this.label1 = new System.Windows.Forms.Label();
  75.             this.panelButtons.SuspendLayout();
  76.             this.panel1.SuspendLayout();
  77.             this.SuspendLayout();
  78.             //
  79.             // panelButtons
  80.             //
  81.             this.panelButtons.Controls.Add(this.btnOK);
  82.             this.panelButtons.Controls.Add(this.btnCancel);
  83.             this.panelButtons.Dock = System.Windows.Forms.DockStyle.Bottom;
  84.             this.panelButtons.Location = new System.Drawing.Point(0, 106);
  85.             this.panelButtons.Name = "panelButtons";
  86.             this.panelButtons.Padding = new System.Windows.Forms.Padding(5);
  87.             this.panelButtons.Size = new System.Drawing.Size(384, 36);
  88.             this.panelButtons.TabIndex = 4;
  89.             //
  90.             // btnOK
  91.             //
  92.             this.btnOK.DialogResult = System.Windows.Forms.DialogResult.OK;
  93.             this.btnOK.Dock = System.Windows.Forms.DockStyle.Right;
  94.             this.btnOK.Location = new System.Drawing.Point(229, 5);
  95.             this.btnOK.Name = "btnOK";
  96.             this.btnOK.Size = new System.Drawing.Size(75, 26);
  97.             this.btnOK.TabIndex = 0;
  98.             this.btnOK.Text = "OK";
  99.             this.btnOK.UseVisualStyleBackColor = true;
  100.             this.btnOK.Click += new System.EventHandler(this.btnOK_Click);
  101.             //
  102.             // btnCancel
  103.             //
  104.             this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
  105.             this.btnCancel.Dock = System.Windows.Forms.DockStyle.Right;
  106.             this.btnCancel.Location = new System.Drawing.Point(304, 5);
  107.             this.btnCancel.Name = "btnCancel";
  108.             this.btnCancel.Size = new System.Drawing.Size(75, 26);
  109.             this.btnCancel.TabIndex = 1;
  110.             this.btnCancel.Text = "Cancel";
  111.             this.btnCancel.UseVisualStyleBackColor = true;
  112.             this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
  113.             //
  114.             // panel1
  115.             //
  116.             this.panel1.Controls.Add(this.inputPassword);
  117.             this.panel1.Controls.Add(this.label2);
  118.             this.panel1.Controls.Add(this.inputUsername);
  119.             this.panel1.Controls.Add(this.label1);
  120.             this.panel1.Dock = System.Windows.Forms.DockStyle.Fill;
  121.             this.panel1.Location = new System.Drawing.Point(0, 0);
  122.             this.panel1.Name = "panel1";
  123.             this.panel1.Padding = new System.Windows.Forms.Padding(10);
  124.             this.panel1.Size = new System.Drawing.Size(384, 106);
  125.             this.panel1.TabIndex = 5;
  126.             //
  127.             // inputPassword
  128.             //
  129.             this.inputPassword.Dock = System.Windows.Forms.DockStyle.Top;
  130.             this.inputPassword.Location = new System.Drawing.Point(10, 76);
  131.             this.inputPassword.Name = "inputPassword";
  132.             this.inputPassword.PasswordChar = '*';
  133.             this.inputPassword.Size = new System.Drawing.Size(364, 20);
  134.             this.inputPassword.TabIndex = 7;
  135.             //
  136.             // label2
  137.             //
  138.             this.label2.AutoSize = true;
  139.             this.label2.Dock = System.Windows.Forms.DockStyle.Top;
  140.             this.label2.Location = new System.Drawing.Point(10, 53);
  141.             this.label2.Name = "label2";
  142.             this.label2.Padding = new System.Windows.Forms.Padding(0, 5, 0, 5);
  143.             this.label2.Size = new System.Drawing.Size(53, 23);
  144.             this.label2.TabIndex = 6;
  145.             this.label2.Text = "Password";
  146.             //
  147.             // inputUsername
  148.             //
  149.             this.inputUsername.Dock = System.Windows.Forms.DockStyle.Top;
  150.             this.inputUsername.Location = new System.Drawing.Point(10, 33);
  151.             this.inputUsername.Name = "inputUsername";
  152.             this.inputUsername.Size = new System.Drawing.Size(364, 20);
  153.             this.inputUsername.TabIndex = 5;
  154.             //
  155.             // label1
  156.             //
  157.             this.label1.AutoSize = true;
  158.             this.label1.Dock = System.Windows.Forms.DockStyle.Top;
  159.             this.label1.Location = new System.Drawing.Point(10, 10);
  160.             this.label1.Name = "label1";
  161.             this.label1.Padding = new System.Windows.Forms.Padding(0, 5, 0, 5);
  162.             this.label1.Size = new System.Drawing.Size(55, 23);
  163.             this.label1.TabIndex = 4;
  164.             this.label1.Text = "Username";
  165.             //
  166.             // XNASignIn
  167.             //
  168.             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
  169.             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
  170.             this.ClientSize = new System.Drawing.Size(384, 142);
  171.             this.Controls.Add(this.panel1);
  172.             this.Controls.Add(this.panelButtons);
  173.             this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
  174.             this.MaximizeBox = false;
  175.             this.MinimizeBox = false;
  176.             this.Name = "XNASignIn";
  177.             this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
  178.             this.Text = "User Login";
  179.             this.panelButtons.ResumeLayout(false);
  180.             this.panel1.ResumeLayout(false);
  181.             this.panel1.PerformLayout();
  182.             this.ResumeLayout(false);
  183.  
  184.         }
  185.  
  186.         protected override void Dispose(bool disposing)
  187.         {
  188.             if (disposing && (components != null))
  189.             {
  190.                 components.Dispose();
  191.             }
  192.             base.Dispose(disposing);
  193.         }
  194.  
  195.         private System.ComponentModel.IContainer components = null;
  196.  
  197.         private System.Windows.Forms.Panel panelButtons;
  198.         private System.Windows.Forms.Button btnOK;
  199.         private System.Windows.Forms.Button btnCancel;
  200.         private System.Windows.Forms.Panel panel1;
  201.         private System.Windows.Forms.TextBox inputPassword;
  202.         private System.Windows.Forms.Label label2;
  203.         private System.Windows.Forms.TextBox inputUsername;
  204.         private System.Windows.Forms.Label label1;
  205.     }
  206. }
Advertisement
Add Comment
Please, Sign In to add comment