Windows窗体:检测聚焦控制的变化 [英] Windows Forms: detect the change of the focused control

查看:136
本文介绍了Windows窗体:检测聚焦控制的变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我执行复制粘贴的Windows窗体应用程序。 我需要启用/禁用栏,按钮,这两个操作,当用户改变了焦点元素的应用程序。

I'm implementing copy-paste in a Windows Forms application. I need to enable/disable the bar-buttons for this two operations when the user changes the focused element in the application.

我可以使用这样的事情找到当前重点控制:的http:// www.syncfusion.com/FAQ/windowsforms/faq_c41c.aspx#q1021q ,但我怎么能检测到集中控制发生了变化?

I can find the current focused control using something like this: http://www.syncfusion.com/FAQ/windowsforms/faq_c41c.aspx#q1021q, but how can I detect that the focused control has changed?

推荐答案

在你的窗体加载事件处理程序,你也可以通过所有包含在形式和每个可获得焦点的控制的控制回路添加事件处理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.");
	}

这篇关于Windows窗体:检测聚焦控制的变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆