如何找到previous主动控制C# [英] How to find previous active control c#

查看:193
本文介绍了如何找到previous主动控制C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发的键盘控制,很简单的嵌入形式。使用sendkey类来进行字符输入。让这个功能是需要知道previous选择的控制。

i am developing keyboard control, very simple embedded on a form. using sendkey class to perform char entry. to make this functional is required to know previous selected control.

推荐答案

类似下面应该做的伎俩:

Something like the following should do the trick:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace DragDropTest
{
    public partial class LostFocusTestForm : Form
    {
    	private Control _lastControl;

    	public LostFocusTestForm()
    	{
    		InitializeComponent();

    		TrapLostFocusOnChildControls(this.Controls);
    	}
    	private void finalTextBox_Enter(object sender, EventArgs e)
    	{
    		MessageBox.Show("From " + _lastControl.Name + " to " + this.ActiveControl.Name);
    	}

    	private void AllLostFocus(object sender, EventArgs e)
    	{
    		_lastControl = (Control)sender;
    	}

    	private void TrapLostFocusOnChildControls(Control.ControlCollection controls)
    	{
    		foreach (Control control in controls)
    		{
    			control.LostFocus += new EventHandler(AllLostFocus);

    			Control.ControlCollection childControls = control.Controls;
    			if (childControls != null)
    				TrapLostFocusOnChildControls(childControls);
    		}
    	}
    }
}

这篇关于如何找到previous主动控制C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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