를 사용하여 컨트롤에 포커스를 설정할 수 있습니다.
textBox에 대해 이렇게하면 select가 입력 포커스를 얻는 것을 확인합니다.
사용자가 선택한 (포커스가있는) 사용자 정의 컨트롤을 사용하여 모양을 변경하거나 컨트롤을 선택하려는 경우가 있습니다.
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
}
private void InitializeComponent()
{
this.checkBox1 = new System.Windows.Forms.CheckBox();
...
this.Enter += new System.EventHandler(this.OnEnterFocus);
this.Leave += new System.EventHandler(this.OnLeaveFocus);
}
private void OnEnterFocus(object sender, EventArgs e)
{
this.checkBox1.Checked = true;
}
private void OnLeaveFocus(object sender, EventArgs e)
{
this.checkBox1.Checked = false;
}
}
이렇게하려면 사용자 컨트롤 클래스는 내가 사용자 컨트롤이 선택 될 때마다 확인되는 체크 박스와 사용자 정의 컨트롤을 만든
이벤트 Control.Enter 및 Control.Leave에 가입한다
나는 버튼으로 형성하고, 버튼을 클릭 할 때 호출되는 이벤트 핸들러를 가지고 : 버튼 내가 확인란이 선택되어 있기 때문에 사용자 컨트롤에 포커스를 얻을 것을 볼 클릭 이제 때마다
private void OnButton1Clicked(object sender, EventArgs e)
{
this.userControl1.Select();
}
다른 곳을 클릭 할 때마다 체크 박스가 나타납니다. 선택하지 않았다.
'UserControls'에는 다른 컨트롤이 포함되어 있습니까? 그렇다면 그 중 하나에 집중할 수 있습니다. – adv12
this.ActiveControl = YourControl; –
다른 사람이 언급 한대로 ActiveControl을 설정하십시오. 또한, 그들은 당신의 UserControls이야! public FocusOnMe() 메서드를 제공하고 포커스를 설정할 위치를 코딩하면 myUserControl.FocusOnMe()를 사용할 수 있습니다. –