내가 접근 할 방법은 UserControl이 만들어지고 디자인 모드에 있지 않을 때 사용자 컨트롤 내의 각 컨트롤을 순환하여 GotFocus 이벤트에 후크를 추가하고 해당 메서드에 대한 후크를 가리키는 것입니다. UserControl (ChildControlGotFocus)은 사용자 정의 컨트롤의 호스트에서 사용할 수있는 이벤트를 발생시킵니다.
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
if (!this.DesignMode)
{
RegisterControls(this.Controls);
}
}
public event EventHandler ChildControlGotFocus;
private void RegisterControls(ControlCollection cControls)
{
foreach (Control oControl in cControls)
{
oControl.GotFocus += new EventHandler(oControl_GotFocus);
if (oControl.HasChildren)
{
RegisterControls(oControl.Controls);
}
}
}
void oControl_GotFocus(object sender, EventArgs e)
{
if (ChildControlGotFocus != null)
{
ChildControlGotFocus(this, new EventArgs());
}
}
}
감사 :
예를 들어, 여기에이 기능을 구현하는 샘플의 UserControl입니다. 네가 한 일에 정말 감사한다. – MahanGM