且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Windows窗体:检测聚焦控制的变化

更新时间:2023-12-06 11:07:04

在你的窗体加载事件处理程序,你也可以通过所有包含在形式和每个可获得焦点的控制的控制回路添加事件处理Enter事件:

In your form load event handler you could also loop through all of the controls contained in the form and for each focusable control add an event handler for the Enter event:

	private void Form1_Load(object sender, EventArgs e)
	{
		foreach (Control control in Controls)
		{
			control.Enter += ControlReceivedFocus;
		}
	}

	void ControlReceivedFocus(object sender, EventArgs e)
	{
		Debug.WriteLine(sender + " received focus.");
	}