不用vs写form

来源:互联网 发布:mysql数据库方言 编辑:程序博客网 时间:2024/05/17 23:28

using System;
using System.Collections.Generic;
using System.Windows.Forms;

public class Form1 : System.Windows.Forms.Form
 {
  private System.Windows.Forms.TextBox txtUserName;
  private System.Windows.Forms.TextBox txtPassword;
  private System.Windows.Forms.Button btnOK;
  private System.Windows.Forms.Button btnCancel;

  private System.ComponentModel.Container components = null;

  private int nLoginCount = 0;
  private const int MAX_LOGIN_COUNT = 3;
  private UserInfo uiLogin;

  public Form1(UserInfo ui)
  {
   InitializeComponent();
            uiLogin = ui;

  }


  protected override void Dispose( bool disposing )
  {
   if( disposing )
   {
    if (components != null)
    {
     components.Dispose();
    }
   }
   base.Dispose( disposing );
  }


  private void InitializeComponent()
  {
   this.txtUserName = new System.Windows.Forms.TextBox();
   this.txtPassword = new System.Windows.Forms.TextBox();
   this.btnOK = new System.Windows.Forms.Button();
   this.btnCancel = new System.Windows.Forms.Button();
   this.SuspendLayout();

   this.txtUserName.Location = new System.Drawing.Point(96, 48);
   this.txtUserName.Name = "txtUserName";
   this.txtUserName.TabIndex = 0;
   this.txtUserName.Text = "";

   this.txtPassword.Location = new System.Drawing.Point(96, 96);
   this.txtPassword.Name = "txtPassword";
   this.txtPassword.PasswordChar = '*';
   this.txtPassword.TabIndex = 1;
   this.txtPassword.Text = "";

   this.btnOK.Location = new System.Drawing.Point(64, 152);
   this.btnOK.Name = "btnOK";
   this.btnOK.TabIndex = 2;
   this.btnOK.Text = "button1";
   this.btnOK.Click += new System.EventHandler(this.btnOK_Click);

   this.btnCancel.Location = new System.Drawing.Point(152, 152);
   this.btnCancel.Name = "btnCancel";
   this.btnCancel.TabIndex = 3;
   this.btnCancel.Text = "button1";
   this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);

   this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
   this.ClientSize = new System.Drawing.Size(292, 266);
   this.Controls.Add(this.btnCancel);
   this.Controls.Add(this.btnOK);
   this.Controls.Add(this.txtPassword);
   this.Controls.Add(this.txtUserName);
   this.Name = "Form1";
   this.Text = "Form1";
   this.ResumeLayout(false);

  }

  [STAThread]
  static void Main()
  {
   UserInfo ui = new UserInfo();
   Application.Run(new Form1(ui));
  }

  private void btnOK_Click(object sender, System.EventArgs e)
  {
   if( txtUserName.Text == "Admin" && txtPassword.Text == "nopassword" )
   {
    // Save login user info
    uiLogin.UserName = txtUserName.Text;
    uiLogin.Password = txtPassword.Text;

    // Set dialog result with OK
    //this.DialogResult = DialogResult.OK;
    MessageBox.Show("The username and password is right!");
   }
   }

  private void btnCancel_Click(object sender, System.EventArgs e)
  {
   this.Close();
  }
 }

 public class UserInfo
 {
  private string strUserName;
  private string strPassword;
  public string UserName
  {
   get{ return strUserName;}
   set{ strUserName = value;   }
  }
  public string Password
  {
   get{ return strPassword;}
   set{ strPassword = value;}
  }
  public UserInfo()
  {
   strUserName = "";
   strPassword = "";
  }
 } 

原创粉丝点击