Control.ControlCollection, () , "Enter", . Active Control Active Control, , ... . , FrameWork 3.5 4.0.
// :
using System;
using System.Collections.Generic;
using System.Windows.Forms;
private static EventHandler _event;
public static void SetEnterEvent(this Control.ControlCollection theCollection, EventHandler theEvent)
{
_event = theEvent;
recurseSetEnter(theCollection);
}
public static void recurseSetEnter(Control.ControlCollection aCollection)
{
foreach (Control theControl in aCollection)
{
if (!String.IsNullOrWhiteSpace(theControl.Name))
{
Console.WriteLine("setting enter handler for : " + theControl.Name + " : " + theControl.GetType().ToString());
theControl.Enter += _event;
}
if (theControl.Controls.Count > 0) recurseSetEnter((Control.ControlCollection)theControl.Controls);
}
}
, : :
, , Enter :
:
public static Control theActiveControl = null;
public static Control thePreviousControl = null;
, :
private void control_enter(object sender, EventArgs e)
{
thePreviousControl = theActiveControl;
theActiveControl = sender as Control;
Console.WriteLine("Active Control is now : " + theActiveControl.Name);
}
Form_Load :
private event EventHandler enter = delegate { };
enter += new EventHandler(control_enter);
, :
this.Controls.SetEnterEvent(enter);
: WinForm ActiveControl: , , :... (, ) , "/"... ActiveControl, // / .. , "ActiveControlChanged".
[edit] "", , , - "" ( ), , ... ... . []
[edit] , , PictureBox, "Enter event", : - , , ", : , PictureBox" ". " "" "(" ControlContainer " ). , , , " ", - . []
, . , , , , , "", :)