Landing box controls
For a long time before things out Liuliu recently, and has not been for the last application of things, a bit unfamiliar! I hope the things this can help you, we discussed the common progress of this article is relatively simple, you are for the landing of a common frame control!
First of all construction projects LoginControl a solution, add a class library project LoginControl, and then add a user control ctlLogin
Then write code in the document ctlLogin.cs
/ / CtlLogin.cs
Using System;
Using System.Collections;
Using System.ComponentModel;
Using System.Drawing;
Using System.Data;
Using System.Windows.Forms;
Using System.Text;
Namespace LoginControl
(
/ / /
/ / / CtlLogin explanatory memorandum.
/ / /
Public class ctlLogin: System.Windows.Forms.UserControl
(
Private System.Windows.Forms.Panel panel1;
Private System.Windows.Forms.Label lHeader;
Private System.Windows.Forms.Label lText;
Private System.Windows.Forms.Button btnLogin;
Private System.Windows.Forms.Label lPassword;
Private System.Windows.Forms.Label lUsername;
Private System.Windows.Forms.TextBox txtPassword;
Private System.Windows.Forms.TextBox txtUsername;
Private System.Windows.Forms.PictureBox pictureBox1;
Private System.Windows.Forms.ErrorProvider errorProvider;
/ / /
/ / / Necessary for the design variables.
/ / /
Private System.ComponentModel.Container components = null;
Public event System.EventHandler Successful;
Public event System.EventHandler Failed;
Private ArrayList strUsername = new ArrayList ();
Private ArrayList strPassword = new ArrayList ();
Private int index =- 1;
Private string ErrMsg = "Please enter the correct user name and password!";
Public ctlLogin ()
(
/ / The call is Windows.Forms form designer necessary.
InitializeComponent ();
/ / TODO: Add after InitializeComponent call any initialization
StrUsername.Clear ();
StrPassword.Clear ();
)
/ / /
/ / / Cleaning is the use of all the resources.
/ / /
Protected override void Dispose (bool disposing)
(
If (disposing)
(
If (components! = Null)
(
Components.Dispose ();
)
)
Base.Dispose (disposing);
)
# Region Component Design generates code
/ / /
/ / / Designer support of the approach - Do not use the code editor
/ / / Modify the content of this method.
/ / /
Private void InitializeComponent ()
(
System.Resources.ResourceManager resources = new System.Resources.ResourceManager (typeof (ctlLogin));
This.panel1 = new System.Windows.Forms.Panel ();
This.pictureBox1 = new System.Windows.Forms.PictureBox ();
This.lText = new System.Windows.Forms.Label ();
This.lHeader = new System.Windows.Forms.Label ();
This.btnLogin = new System.Windows.Forms.Button ();
This.lPassword = new System.Windows.Forms.Label ();
This.lUsername = new System.Windows.Forms.Label ();
This.txtPassword = new System.Windows.Forms.TextBox ();
This.txtUsername = new System.Windows.Forms.TextBox ();
This.errorProvider = new System.Windows.Forms.ErrorProvider ();
This.panel1.SuspendLayout ();
This.SuspendLayout ();
/ /
/ / Panel1
/ /
This.panel1.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
This.panel1.Controls.Add (this.pictureBox1);
This.panel1.Controls.Add (this.lText);
This.panel1.Controls.Add (this.lHeader);
This.panel1.Location = new System.Drawing.Point (4, 4);
This.panel1.Name = "panel1";
This.panel1.Size = new System.Drawing.Size (480, 52);
This.panel1.TabIndex = 0;
/ /
/ / PictureBox1
/ /
This.pictureBox1.Image = ((System.Drawing.Image) (resources.GetObject ( "pictureBox1.Image ")));
This.pictureBox1.Location = new System.Drawing.Point (432, 12);
This.pictureBox1.Name = "pictureBox1";
This.pictureBox1.Size = new System.Drawing.Size (40, 32);
This.pictureBox1.TabIndex = 6;
This.pictureBox1.TabStop = false;
/ /
/ / LText
/ /
This.lText.Location = new System.Drawing.Point (36, 24);
This.lText.Name = "lText";
This.lText.Size new System.Drawing.Size = (360, 20);
This.lText.TabIndex = 5;
This.lText.Text = "Please enter your user name and password.";
This.lText.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
/ /
/ / LHeader
/ /
This.lHeader.Font = new System.Drawing.Font ( "Tahoma" 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte) (0)));
This.lHeader.Location = new System.Drawing.Point (12, 4);
This.lHeader.Name = "lHeader";
This.lHeader.Size new System.Drawing.Size = (384, 20);
This.lHeader.TabIndex = 4;
This.lHeader.Text = "landing";
This.lHeader.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
/ /
/ / BtnLogin
/ /
This.btnLogin.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
This.btnLogin.Font = new System.Drawing.Font ( "Tahoma" 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte) (0)));
This.btnLogin.Location = new System.Drawing.Point (376, 292);
This.btnLogin.Name = "btnLogin";
This.btnLogin.Size = new System.Drawing.Size (70, 20);
This.btnLogin.TabIndex = 14;
This.btnLogin.Text = "landing";
This.btnLogin.Click + = new System.EventHandler (this.btnLogin_Click);
/ /
/ / LPassword
/ /
This.lPassword.Font = new System.Drawing.Font ( "Tahoma" 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte) (0)));
This.lPassword.Location = new System.Drawing.Point (76, 252);
This.lPassword.Name = "lPassword";
This.lPassword.Size = new System.Drawing.Size (80, 20);
This.lPassword.TabIndex = 16;
This.lPassword.Text = "password";
This.lPassword.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
/ /
/ / LUsername
/ /
This.lUsername.Font = new System.Drawing.Font ( "Tahoma" 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte) (0)));
This.lUsername.Location = new System.Drawing.Point (76, 212);
This.lUsername.Name = "lUsername";
This.lUsername.Size = new System.Drawing.Size (80, 20);
This.lUsername.TabIndex = 15;
This.lUsername.Text = "user name";
This.lUsername.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
/ /
/ / TxtPassword
/ /
This.txtPassword.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
This.txtPassword.Location = new System.Drawing.Point (176, 252);
This.txtPassword.Name = "txtPassword";
This.txtPassword.PasswordChar = '*';
This.txtPassword.Size new System.Drawing.Size = (270, 21);
This.txtPassword.TabIndex = 13;
This.txtPassword.Text = "";
This.txtPassword.KeyPress + = new System.Windows.Forms.KeyPressEventHandler (this.txtPassword_KeyPress);
This.txtPassword.Leave + = new System.EventHandler (this.Control_Leave);
This.txtPassword.Enter + = new System.EventHandler (this.Control_Enter);
/ /
/ / TxtUsername
/ /
This.txtUsername.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
This.txtUsername.Location = new System.Drawing.Point (176, 212);
This.txtUsername.Name = "txtUsername";
This.txtUsername.Size new System.Drawing.Size = (270, 21);
This.txtUsername.TabIndex = 12;
This.txtUsername.Text = "";
This.txtUsername.KeyPress + = new System.Windows.Forms.KeyPressEventHandler (this.txtUsername_KeyPress);
This.txtUsername.Leave + = new System.EventHandler (this.Control_Leave);
This.txtUsername.Enter + = new System.EventHandler (this.Control_Enter);
/ /
/ / ErrorProvider
/ /
This.errorProvider.ContainerControl = this;
/ /
/ / CtlLogin
/ /
This.Controls.Add (this.btnLogin);
This.Controls.Add (this.lPassword);
This.Controls.Add (this.lUsername);
This.Controls.Add (this.txtPassword);
This.Controls.Add (this.txtUsername);
This.Controls.Add (this.panel1);
This.Name = "ctlLogin";
This.Size = new System.Drawing.Size (484, 348);
This.Load + = new System.EventHandler (this.ctlLogin_Load);
This.panel1.ResumeLayout (false);
This.ResumeLayout (false);
)
# Endregion
Private void ctlLogin_Load (object sender, System.EventArgs e)
(
/ / StrUsername.Add (txtUsername.Text.Trim ());
/ / StrPassword.Add (txtPassword.Text.Trim ());
)
Private void txtPassword_KeyPress (object sender, System.Windows.Forms.KeyPressEventArgs e)
(
If (e.KeyChar == (char) 13)
(
BtnLogin_Click (sender, new EventArgs ());
)
)
Private void btnLogin_Click (object sender, System.EventArgs e)
(
Bool b = CheckPassword (Username, Password);
If (b)
(
Successful (this, new System.EventArgs ());
)
Else
(
Failed (this, new System.EventArgs ());
)
)
/ / /
/ / / Judgement user name and password are correct
/ / /
/ / /
All users / / /
All user passwords / / /
Private bool CheckPassword (ArrayList alUser, ArrayList alPWD)
(
String strUser = "";
String strPWD = "";
If (alUser.Count> 0 & & alPWD.Count> 0)
(
For (int i = 0; i
StrUser [i] = alUser. ToString ();
StrPWD [i] = alPWD. ToString (). Trim ();
If (strUser.Trim () == txtUsername.Text.Trim () & & strPWD.Trim () == txtPassword.Text.Trim ())
(
Index_Username = i;
ErrorProvider.Dispose ();
Return true;
)
If (i == alUser.Count-1)
(
ErrorProvider.SetError (btnLogin, ErrMsg);
Return false;
)
)
)
Return false;
)
Private void Control_Enter (object sender, System.EventArgs e)
(
Control ctl = (Control) sender;
Ctl.BackColor = Color.LemonChiffon;
)
Private void Control_Leave (object sender, System.EventArgs e)
(
Control ctl = (Control) sender;
Ctl.BackColor = Color.White;
)
Private void txtUsername_KeyPress (object sender, System.Windows.Forms.KeyPressEventArgs e)
(
If (e.KeyChar == (char) 13)
(
TxtPassword.Focus ();
)
)
/ / /
/ / / All users
/ / /
Public ArrayList Username
(
Get
(
Return strUsername;
)
Set
(
StrUsername = value;
)
)
/ / /
/ / / Passwords for all users
/ / /
Public ArrayList Password
(
Get
(
Return strPassword;
)
Set
(
StrPassword = value;
)
)
/ / /
/ / / User in the array Username Index
/ / /
Public int Index_Username
(
Get
(
Return index;
)
Set
(
Index = value;
)
)
/ / /
/ / / Error message
/ / /
Public string ErrorMessage
(
Get
(
Return ErrMsg;
)
Set
(
ErrMsg = value;
)
)
)
)
Then, you can compile into LoginControl.dll
Then add in resolving the project a test project Test, and then in the toolbox in Add / Remove item compiled LoginControl.dll just add, add a test for frmTest interface, and then in the toolbox controls until frmTest page ctlLogin in the face
Then frmTest.cs to test earlier in the controls
/ / FrmTest.cs
Using System;
Using System.Drawing;
Using System.Collections;
Using System.ComponentModel;
Using System.Windows.Forms;
Using System.Data;
Using InformationClass; / / to write a test-class
Namespace Test
(
/ / /
/ / / Summary of the Form1.
/ / /
Public class frmTest: System.Windows.Forms.Form
(
Private LoginControl.ctlLogin ctlLogin;
/ / /
/ / / Necessary for the design variables.
/ / /
Private System.ComponentModel.Container components = null;
Private Users objUsers = new Users (); / / examples of user-defined collections landing
Private User m_objUser = new User () / / examples of user-defined categories landing
Public frmTest ()
(
/ /
/ / Windows Forms designer support necessary
/ /
InitializeComponent ();
/ /
/ / TODO: Add after InitializeComponent call any constructor code
/ /
)
/ / /
/ / / Cleaning is the use of all the resources.
/ / /
Protected override void Dispose (bool disposing)
(
If (disposing)
(
If (components! = Null)
(
Components.Dispose ();
)
)
Base.Dispose (disposing);
)
# Region Windows Forms designer generated code
/ / /
/ / / Designer support of the approach - Do not use the code editor Laws
/ / / The contents of this method.
/ / /
Private void InitializeComponent ()
(
System.Resources.ResourceManager resources = new System.Resources.ResourceManager (typeof (frmTest));
This.ctlLogin = new LoginControl.ctlLogin ();
This.SuspendLayout ();
/ /
/ / CtlLogin
/ /
This.ctlLogin.ErrorMessage = "Please enter the correct user name and password!";
This.ctlLogin.Index_Username = -1;
This.ctlLogin.Location new System.Drawing.Point = (0, 0);
This.ctlLogin.Name = "ctlLogin";
This.ctlLogin.Size = new System.Drawing.Size (484, 348);
This.ctlLogin.TabIndex = 0;
This.ctlLogin.Failed + = new System.EventHandler (this.ctlLogin_Failed);
This.ctlLogin.Load + = new System.EventHandler (this.Form1_Load);
This.ctlLogin.Successful + = new System.EventHandler (this.ctlLogin_Successful);
/ /
/ / FrmTest
/ /
This.AutoScaleBaseSize = new System.Drawing.Size (6, 14);
This.ClientSize = new System.Drawing.Size (484, 345);
This.Controls.Add (this.ctlLogin);
This.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
This.Icon = ((System.Drawing.Icon) (resources.GetObject ( "$ this.Icon ")));
This.MaximizeBox = false;
This.MinimizeBox = false;
This.Name = "frmTest";
This.Text = "landing system";
This.Load + = new System.EventHandler (this.Form1_Load);
This.ResumeLayout (false);
)
# Endregion
/ / /
/ / / Application's main entrance point.
/ / /
[STAThread]
Static void Main ()
(
Application.Run (new frmTest ());
)
Private void ctlLogin_Failed (object sender, System.EventArgs e)
(
MessageBox.Show ( "landing failed! Please enter the correct user name and password information !!"," tips," MessageBoxButtons.OK, MessageBoxIcon.Error);
)
Private void ctlLogin_Successful (object sender, System.EventArgs e)
(
ObjUsers m_objUser = [ctlLogin.Index_Username];
MessageBox.Show ( "successful landing!", "Information Tip" MessageBoxButtons.OK, MessageBoxIcon.Information);
)
Private void Form1_Load (object sender, System.EventArgs e)
(
ObjUsers = new ReadData (). GetUsers ();
If (objUsers.Count> 0)
(
Foreach (User objUser in objUsers)
(
CtlLogin.Username.Add (objUser.Name);
CtlLogin.Password.Add (objUser.Password);
)
)
)
)
)
Operational procedures
If the landing there will be failure
If successful landing
In this way, a little on the controls for the landing, I hope that the article can learn not just for how long. NET programmers help if there are any deficiencies in and hope you will correct me, thank you








0 Comments to “Landing box controls”
No Comments. Send your comment.
Leave a Reply
You must be logged in to post a comment.