你用一个变量,当点击某个textbox时,就记下它的id就可以了,可以在textbox的获得焦点的事件里写!
解决方案 »
- 求助。。
- 如何避免winform加载数据库连接时出现界面假死的问题
- 请问这个Insert into问题如何解决
- 小妹求助,如何用程序启动另一个打开的VS2005工程
- 大家好,有个关于读取数据库中xml字段值的小问题,谢谢大家
- 通过div.innerhtml 动态加载用户控件??
- 新建数据库,即新建帐套
- 宿主程序为windows服务的remoting ,为什么在windows服务里读取配置文件,总是异常?
- ★★谁来帮我看看下面的几行语句添加记录时为什么出现列不属于表?☆UP有分☆
- 怎样获取一个数据源?
- ¥取得本地驱动器后,如何判断他们是光驱、软驱还是硬盘呢?¥
- 又是菜鸟问题,给没有焦点的应用程序窗口发送组合键消息!例如:ALT+A
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获得焦点!");
}
}
}
{
foreach(Control con in this.Controls)
{
if (con.GetType().Name.ToUpper().Equals("TEXTBOX"))
{
if (con.Focused)
return (TextBox)con;
}
}
return null;
}