以前在WinForms中集中控制 [英] Previous focused control in WinForms

查看:279
本文介绍了以前在WinForms中集中控制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个有很多控制的胜利表格:



我想知道用户何时在输入txt1之后输入txt2。换句话说,当用户在'txt2'我想知道是以前的控制'txt1'或不。

这样的事情最好的办法是什么?

解决方案

可以只保留一个控制类型的模块级别的变量来存储最后一个控件的焦点。由于您需要跟踪每个接收焦点的控件,因此每个控件都需要为Enter事件订阅公共事件处理程序。在这种情况下,你将把已经输入的控件分配给模块级的变量,但在此之前,你可以测试'txt1'和'txt2'之间的跳转。


I have a win form with lot of controls:

I want to know when user enters 'txt2' exactly after he entered 'txt1'. In other words when user is in 'txt2' I want to know was previous control 'txt1' or not.

What is the best way to such thing?

解决方案

You could just keep a module-level variable of the type Control that stores the last control to receive focus. Since you need to keep track of each control which receives focus, each control needs to subscribe to a common event handler for the Enter event. In that event you will assign the control that has been entered to the module-level variable, but before that you can test for the jump between 'txt1' and 'txt2'.

这篇关于以前在WinForms中集中控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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