你用一个变量,当点击某个textbox时,就记下它的id就可以了,可以在textbox的获得焦点的事件里写!

解决方案 »

  1.   

    返回他们的各自的Focused就OK拉
      

  2.   

    如楼上所说,
    using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;
    using System.Data;namespace WindowsApplication1
    {
    /// <summary>
    /// Form1 的摘要说明。
    /// </summary>
    public class Form1 : System.Windows.Forms.Form
    {
    private System.Windows.Forms.Button button1;
    private System.Windows.Forms.TextBox textBox1;
    private System.Windows.Forms.TextBox textBox2;
    private System.Windows.Forms.TextBox textBox3;
    /// <summary>
    /// 必需的设计器变量。
    /// </summary>
    private System.ComponentModel.Container components = null;
    private int id=0; public Form1()
    {
    //
    // Windows 窗体设计器支持所必需的
    //
    InitializeComponent(); //
    // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
    //
    } /// <summary>
    /// 清理所有正在使用的资源。
    /// </summary>
    protected override void Dispose( bool disposing )
    {
    if( disposing )
    {
    if (components != null) 
    {
    components.Dispose();
    }
    }
    base.Dispose( disposing );
    }
    /// <summary>
    /// 应用程序的主入口点。
    /// </summary>
    [STAThread]
    static void Main() 
    {
    Application.Run(new Form1());
    } private void textBox1_Enter(object sender, System.EventArgs e)
    {
      id=1;
    } private void textBox2_Enter(object sender, System.EventArgs e)
    {
      id=2;
    } private void textBox3_Enter(object sender, System.EventArgs e)
    {
      id=3;
    } private void button1_Click(object sender, System.EventArgs e)
    {
    if(id>0)
    MessageBox.Show("第"+id.ToString()+"个TEXTBOX获得焦点!");
    }
    }
    }
      

  3.   

    private TextBox GetFocused()
    {
    foreach(Control con in this.Controls)
    {
    if (con.GetType().Name.ToUpper().Equals("TEXTBOX"))
    {
    if (con.Focused)
    return (TextBox)con;
    }
    }
    return null;
    }