代码如下:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;namespace member
{
/// <summary>
/// login 的摘要说明。
/// </summary>
public class login : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.TextBox textBox3;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null; public login()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent(); //
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
} /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows Form Designer generated code
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(login));
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.textBox3 = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.SuspendLayout();
// 
// button1
// 
this.button1.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
this.button1.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.button1.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.button1.Location = new System.Drawing.Point(280, 184);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(56, 24);
this.button1.TabIndex = 3;
this.button1.Text = "确  定";
this.button1.Click += new System.EventHandler(this.button1_Click);
// 
// button2
// 
this.button2.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
this.button2.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.button2.Location = new System.Drawing.Point(368, 184);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(56, 24);
this.button2.TabIndex = 4;
this.button2.Text = "取  消";
this.button2.Click += new System.EventHandler(this.button2_Click);
// 
// textBox1
// 
this.textBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.textBox1.Location = new System.Drawing.Point(272, 104);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(160, 21);
this.textBox1.TabIndex = 0;
this.textBox1.Text = "";
// 
// textBox2
// 
this.textBox2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.textBox2.Enabled = false;
this.textBox2.Location = new System.Drawing.Point(272, 128);
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(160, 21);
this.textBox2.TabIndex = 1;
this.textBox2.Text = "";
// 
// textBox3
// 
this.textBox3.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.textBox3.Location = new System.Drawing.Point(272, 152);
this.textBox3.Name = "textBox3";
this.textBox3.PasswordChar = '*';
this.textBox3.Size = new System.Drawing.Size(160, 21);
this.textBox3.TabIndex = 2;
this.textBox3.Text = "";
// 
// label1
// 
this.label1.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
this.label1.Location = new System.Drawing.Point(208, 109);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(72, 16);
this.label1.TabIndex = 5;
this.label1.Text = "用户代码:";
// 
// label2
// 
this.label2.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
this.label2.Location = new System.Drawing.Point(208, 133);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(72, 16);
this.label2.TabIndex = 6;
this.label2.Text = "用户姓名:";
// 
// label3
// 
this.label3.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
this.label3.Location = new System.Drawing.Point(208, 157);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(72, 16);
this.label3.TabIndex = 7;
this.label3.Text = "用户密码:";
// 
// login
// 
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.BackgroundImage = ((System.Drawing.Bitmap)(resources.GetObject("$this.BackgroundImage")));
this.ClientSize = new System.Drawing.Size(448, 229);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
  this.textBox3,
  this.textBox2,
  this.textBox1,
  this.button2,
  this.button1,
  this.label1,
  this.label2,
  this.label3});
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "login";
this.Text = "会员登录";
this.ResumeLayout(false); }
#endregion private void button1_Click(object sender, System.EventArgs e)
{

if (this.CheckUser(this.textBox1.Text.Trim(),this.textBox2.Text.Trim(),this.textBox3.Text.Trim())==true)
{
winmain winmain = new winmain();
classa.Code =textBox1.Text;
classa.User =textBox2.Text;
winmain.Show();
this.Hide();
}
else
{
MessageBox.Show("您输入的帐号或密码有误,请重新登录!","错误",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
} } private void button2_Click(object sender, System.EventArgs e)
{
Application.Exit ();
}
private void textBox1_Enter(object sender, System.EventArgs e)
{
Application.Exit ();
}
private bool CheckUser(string Code,string UserName,string Password)
{
bool IsIn=false;
string source="server=localhost;"+
"uid=sa;pwd=ntdba;"+
"database=zyhx";
string select="select * from admin where code='" + Code.Trim() + "' and passwd='" + Password.Trim() + "'";
try
{
SqlConnection conn = new SqlConnection(source);
conn.Open();
SqlCommand cmd = new SqlCommand(select,conn);
SqlDataReader sql = cmd.ExecuteReader();
while (sql.Read())
{
textBox2.Text = sql["user"].ToString ();
IsIn=true;
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
//conn.Close();
return IsIn;
}
[STAThread] static void Main() 
{
login newmain=new login();
Application.Run(newmain);
}
}
}
我想实现,当textbox1输入完毕后,textbox2自动从数据库中读取数据并显示。

解决方案 »

  1.   

    当textbox1失去焦点时从数据库中取值不就行了!
      

  2.   

    问题我不知道如何使TEXTBOX1失去焦点
      

  3.   

    是这样吗?private void textBox1_Leave(object sender, System.EventArgs e){
    ……
      

  4.   

    private void textBox1_Leave(object sender, System.EventArgs e){
    textBox2.Text = "aa";
    }我加了怎么无效啊?
      

  5.   

    private void WipTextBox_Leave(object sender, System.EventArgs e)
    {
    if(!this.ReadOnly)
    {
    textBox2.Text = "aa";
    }
    }
      

  6.   

    怎么会无效,在textBox1输入,再把焦点移到textBox2或界面上其他控件,这个事件就会触发
      

  7.   

    问题是它没有触发啊。我把代码贴出来,帮我看看。
    using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;
    using System.Data;
    using System.Data.SqlClient;namespace member
    {
    /// <summary>
    /// login 的摘要说明。
    /// </summary>
    public class login : System.Windows.Forms.Form
    {
    private System.Windows.Forms.TextBox textBox1;
    private System.Windows.Forms.TextBox textBox2;
    private System.Windows.Forms.TextBox textBox3;
    private System.Windows.Forms.Button button1;
    private System.Windows.Forms.Button button2;
    private System.Windows.Forms.Label label1;
    private System.Windows.Forms.Label label2;
    private System.Windows.Forms.Label label3;
    /// <summary>
    /// 必需的设计器变量。
    /// </summary>
    private System.ComponentModel.Container components = null; public login()
    {
    //
    // Windows 窗体设计器支持所必需的
    //
    InitializeComponent(); //
    // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
    //
    } /// <summary>
    /// 清理所有正在使用的资源。
    /// </summary>
    protected override void Dispose( bool disposing )
    {
    if( disposing )
    {
    if(components != null)
    {
    components.Dispose();
    }
    }
    base.Dispose( disposing );
    } #region Windows Form Designer generated code
    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {
    System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(login));
    this.button1 = new System.Windows.Forms.Button();
    this.button2 = new System.Windows.Forms.Button();
    this.textBox1 = new System.Windows.Forms.TextBox();
    this.textBox2 = new System.Windows.Forms.TextBox();
    this.textBox3 = new System.Windows.Forms.TextBox();
    this.label1 = new System.Windows.Forms.Label();
    this.label2 = new System.Windows.Forms.Label();
    this.label3 = new System.Windows.Forms.Label();
    this.SuspendLayout();
    // 
    // button1
    // 
    this.button1.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
    this.button1.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
    this.button1.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
    this.button1.Location = new System.Drawing.Point(280, 184);
    this.button1.Name = "button1";
    this.button1.Size = new System.Drawing.Size(56, 24);
    this.button1.TabIndex = 3;
    this.button1.Text = "确  定";
    this.button1.Click += new System.EventHandler(this.button1_Click);
    // 
    // button2
    // 
    this.button2.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
    this.button2.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
    this.button2.Location = new System.Drawing.Point(368, 184);
    this.button2.Name = "button2";
    this.button2.Size = new System.Drawing.Size(56, 24);
    this.button2.TabIndex = 4;
    this.button2.Text = "取  消";
    this.button2.Click += new System.EventHandler(this.button2_Click);
    // 
    // textBox1
    // 
    this.textBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
    this.textBox1.Location = new System.Drawing.Point(272, 104);
    this.textBox1.Name = "textBox1";
    this.textBox1.Size = new System.Drawing.Size(160, 21);
    this.textBox1.TabIndex = 0;
    this.textBox1.Text = "";
    // 
    // textBox2
    // 
    this.textBox2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
    this.textBox2.Enabled = false;
    this.textBox2.Location = new System.Drawing.Point(272, 128);
    this.textBox2.Name = "textBox2";
    this.textBox2.Size = new System.Drawing.Size(160, 21);
    this.textBox2.TabIndex = 1;
    this.textBox2.Text = "";
    // 
    // textBox3
    // 
    this.textBox3.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
    this.textBox3.Location = new System.Drawing.Point(272, 152);
    this.textBox3.Name = "textBox3";
    this.textBox3.PasswordChar = '*';
    this.textBox3.Size = new System.Drawing.Size(160, 21);
    this.textBox3.TabIndex = 2;
    this.textBox3.Text = "";
    // 
    // label1
    // 
    this.label1.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
    this.label1.Location = new System.Drawing.Point(208, 109);
    this.label1.Name = "label1";
    this.label1.Size = new System.Drawing.Size(72, 16);
    this.label1.TabIndex = 5;
    this.label1.Text = "用户代码:";
    // 
    // label2
    // 
    this.label2.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
    this.label2.Location = new System.Drawing.Point(208, 133);
    this.label2.Name = "label2";
    this.label2.Size = new System.Drawing.Size(72, 16);
    this.label2.TabIndex = 6;
    this.label2.Text = "用户姓名:";
    // 
    // label3
    // 
    this.label3.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
    this.label3.Location = new System.Drawing.Point(208, 157);
    this.label3.Name = "label3";
    this.label3.Size = new System.Drawing.Size(72, 16);
    this.label3.TabIndex = 7;
    this.label3.Text = "用户密码:";
    // 
    // login
    // 
    this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
    this.BackgroundImage = ((System.Drawing.Bitmap)(resources.GetObject("$this.BackgroundImage")));
    this.ClientSize = new System.Drawing.Size(448, 229);
    this.Controls.AddRange(new System.Windows.Forms.Control[] {
      this.textBox3,
      this.textBox2,
      this.textBox1,
      this.button2,
      this.button1,
      this.label1,
      this.label2,
      this.label3});
    this.MaximizeBox = false;
    this.MinimizeBox = false;
    this.Name = "login";
    this.Text = "会员登录";
    this.ResumeLayout(false); }
    #endregion private void button1_Click(object sender, System.EventArgs e)
    {

    if (this.CheckUser(this.textBox1.Text.Trim(),this.textBox2.Text.Trim(),this.textBox3.Text.Trim())==true)
    {
    winmain winmain = new winmain();
    classa.Code =textBox1.Text;
    classa.User =textBox2.Text;
    winmain.Show();
    this.Hide();
    }
    else
    {
    MessageBox.Show("您输入的帐号或密码有误,请重新登录!","错误",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
    } } private void button2_Click(object sender, System.EventArgs e)
    {
    Application.Exit ();
    }
    private void textBox1_Enter(object sender, System.EventArgs e)
    {
    Application.Exit ();
    }
    private bool CheckUser(string Code,string UserName,string Password)
    {
    bool IsIn=false;
    string source="server=localhost;"+
    "uid=sa;pwd=ntdba;"+
    "database=zyhx";
    string select="select * from admin where code='" + Code.Trim() + "' and passwd='" + Password.Trim() + "'";
    try
    {
    SqlConnection conn = new SqlConnection(source);
    conn.Open();
    SqlCommand cmd = new SqlCommand(select,conn);
    SqlDataReader sql = cmd.ExecuteReader();
    while (sql.Read())
    {
    textBox2.Text = sql["user"].ToString ();
    IsIn=true;
    }
    }
    catch(Exception ex)
    {
    MessageBox.Show(ex.Message);
    }
    //conn.Close();
    return IsIn;
    }
    [STAThread] private void textBox1_Leave(object sender, System.EventArgs e) {
    textBox2.Text = "aa";
    } static void Main() 
    {
    login newmain=new login();
    Application.Run(newmain);
    }
    }
    }
      

  8.   

    在InitializeComponent里面看不到事件注册,也许丢失了,手动注册一下吧
      

  9.   

    看看InitializeComponent这个里面是否有这个失去焦点的事件,没有就手工加上就ok了
      

  10.   

    TextBox裡面有個Validated事件,在事件內查詢出你要顯示的數據,條件是TextBox內的值
      

  11.   

    我想实现,当textbox1输入完毕后,textbox2自动从数据库中读取数据并显示。
    ---------------------------------------------------------------------
    这个用"焦点"去判断,在winform是很难实现的,且也不稳定,一般的做法是"当textbox1输入完毕后,按回车键执行查询",你的需求如果改成这样就容易实现多了
      

  12.   

    InitializeComponent这个里面,都没有看到事件注册.
    在它里面加上this.textBox1.Click += new System.EventHandler(this.textBox1_Leave);
    就行了
      

  13.   

    试试下面的代码:using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;
    using System.Data;
    using System.Data.SqlClient;namespace member
    {
    /// <summary>
    /// login 的摘要说明。
    /// </summary>
    public class login : System.Windows.Forms.Form
    {
    private System.Windows.Forms.TextBox textBox1;
    private System.Windows.Forms.TextBox textBox2;
    private System.Windows.Forms.TextBox textBox3;
    private System.Windows.Forms.Button button1;
    private System.Windows.Forms.Button button2;
    private System.Windows.Forms.Label label1;
    private System.Windows.Forms.Label label2;
    private System.Windows.Forms.Label label3;
    /// <summary>
    /// 必需的设计器变量。
    /// </summary>
    private System.ComponentModel.Container components = null;public login()
    {
    //
    // Windows 窗体设计器支持所必需的
    //
    InitializeComponent();//
    // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
    //
    }/// <summary>
    /// 清理所有正在使用的资源。
    /// </summary>
    protected override void Dispose( bool disposing )
    {
    if( disposing )
    {
    if(components != null)
    {
    components.Dispose();
    }
    }
    base.Dispose( disposing );
    }#region Windows Form Designer generated code
    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {
    System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(login));
    this.button1 = new System.Windows.Forms.Button();
    this.button2 = new System.Windows.Forms.Button();
    this.textBox1 = new System.Windows.Forms.TextBox();
    this.textBox2 = new System.Windows.Forms.TextBox();
    this.textBox3 = new System.Windows.Forms.TextBox();
    this.label1 = new System.Windows.Forms.Label();
    this.label2 = new System.Windows.Forms.Label();
    this.label3 = new System.Windows.Forms.Label();
    this.SuspendLayout();
    // 
    // button1
    // 
    this.button1.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
    this.button1.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
    this.button1.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
    this.button1.Location = new System.Drawing.Point(280, 184);
    this.button1.Name = "button1";
    this.button1.Size = new System.Drawing.Size(56, 24);
    this.button1.TabIndex = 3;
    this.button1.Text = "确  定";
    this.button1.Click += new System.EventHandler(this.button1_Click);
    // 
    // button2
    // 
    this.button2.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
    this.button2.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
    this.button2.Location = new System.Drawing.Point(368, 184);
    this.button2.Name = "button2";
    this.button2.Size = new System.Drawing.Size(56, 24);
    this.button2.TabIndex = 4;
    this.button2.Text = "取  消";
    this.button2.Click += new System.EventHandler(this.button2_Click);
    // 
    // textBox1
    // 
    this.textBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
    this.textBox1.Location = new System.Drawing.Point(272, 104);
    this.textBox1.Name = "textBox1";
    this.textBox1.Size = new System.Drawing.Size(160, 21);
    this.textBox1.TabIndex = 0;
    this.textBox1.Text = "";
    this.textBox1.Leave += new System.EventHandler(this.textBox1_Leave);
    // 
    // textBox2
    // 
    this.textBox2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
    this.textBox2.Enabled = false;
    this.textBox2.Location = new System.Drawing.Point(272, 128);
    this.textBox2.Name = "textBox2";
    this.textBox2.Size = new System.Drawing.Size(160, 21);
    this.textBox2.TabIndex = 1;
    this.textBox2.Text = "";
    // 
    // textBox3
    // 
    this.textBox3.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
    this.textBox3.Location = new System.Drawing.Point(272, 152);
    this.textBox3.Name = "textBox3";
    this.textBox3.PasswordChar = '*';
    this.textBox3.Size = new System.Drawing.Size(160, 21);
    this.textBox3.TabIndex = 2;
    this.textBox3.Text = "";
    // 
    // label1
    // 
    this.label1.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
    this.label1.Location = new System.Drawing.Point(208, 109);
    this.label1.Name = "label1";
    this.label1.Size = new System.Drawing.Size(72, 16);
    this.label1.TabIndex = 5;
    this.label1.Text = "用户代码:";
    // 
    // label2
    // 
    this.label2.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
    this.label2.Location = new System.Drawing.Point(208, 133);
    this.label2.Name = "label2";
    this.label2.Size = new System.Drawing.Size(72, 16);
    this.label2.TabIndex = 6;
    this.label2.Text = "用户姓名:";
    // 
    // label3
    // 
    this.label3.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
    this.label3.Location = new System.Drawing.Point(208, 157);
    this.label3.Name = "label3";
    this.label3.Size = new System.Drawing.Size(72, 16);
    this.label3.TabIndex = 7;
    this.label3.Text = "用户密码:";
    // 
    // login
    // 
    this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
    this.BackgroundImage = ((System.Drawing.Bitmap)(resources.GetObject("$this.BackgroundImage")));
    this.ClientSize = new System.Drawing.Size(448, 229);
    this.Controls.AddRange(new System.Windows.Forms.Control[] {
      this.textBox3,
      this.textBox2,
      this.textBox1,
      this.button2,
      this.button1,
      this.label1,
      this.label2,
      this.label3});
    this.MaximizeBox = false;
    this.MinimizeBox = false;
    this.Name = "login";
    this.Text = "会员登录";
    this.ResumeLayout(false);}
    #endregionprivate void button1_Click(object sender, System.EventArgs e)
    {if (this.CheckUser(this.textBox1.Text.Trim(),this.textBox2.Text.Trim(),this.textBox3.Text.Trim())==true)
    {
    winmain winmain = new winmain();
    classa.Code =textBox1.Text;
    classa.User =textBox2.Text;
    winmain.Show();
    this.Hide();
    }
    else
    {
    MessageBox.Show("您输入的帐号或密码有误,请重新登录!","错误",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
    }}private void button2_Click(object sender, System.EventArgs e)
    {
    Application.Exit ();
    }
    private void textBox1_Enter(object sender, System.EventArgs e)
    {
    Application.Exit ();
    }
    private bool CheckUser(string Code,string UserName,string Password)
    {
    bool IsIn=false;
    string source="server=localhost;"+
    "uid=sa;pwd=ntdba;"+
    "database=zyhx";
    string select="select * from admin where code='" + Code.Trim() + "' and passwd='" + Password.Trim() + "'";
    try
    {
    SqlConnection conn = new SqlConnection(source);
    conn.Open();
    SqlCommand cmd = new SqlCommand(select,conn);
    SqlDataReader sql = cmd.ExecuteReader();
    while (sql.Read())
    {
    textBox2.Text = sql["user"].ToString ();
    IsIn=true;
    }
    }
    catch(Exception ex)
    {
    MessageBox.Show(ex.Message);
    }
    //conn.Close();
    return IsIn;
    }
    [STAThread]private void textBox1_Leave(object sender, System.EventArgs e){
    textBox2.Text = "aa";
    }static void Main() 
    {
    login newmain=new login();
    Application.Run(newmain);
    }
    }
    }
      

  14.   

    同意tipboy(想做技术边缘人) 的办法,使用自定义验证控件,在验证函数内实现回调即可
      

  15.   

    看msdn关于textbox控件的事件说明。