등록 정보에서 true의 KeyPreview 속성을 true로 설정하십시오.
, 당신의 양식 당신의 양식의 keyDownEvent에서
에 keyDownEvent 추가 코드
코드
if(e.KeyValue==13)// When Enter Key is Pressed
{
// Last line is performing click. Other lines are making sure
// that user is not writing in a Text box
Control ct = userControl1 as Control;
ContainerControl cc = ct as ContainerControl;
if (!(cc.ActiveControl is TextBox))
validationButton.PerformClick(); // Code line to performClick
}
if(e.KeyValue==27) // When Escape Key is Pressed
{
// Last line is performing click. Other lines are making sure
// that user is not writing in a Text box
Control ct = userControl1 as Control;
ContainerControl cc = ct as ContainerControl;
if (!(cc.ActiveControl is TextBox))
cancelButton.PerformClick(); // Code line to performClick
}
의 다음 줄을 포함
validationButton 또는 취소 버튼이의 이름입니다 당신의 내가 방금 가정하고있는 버튼. 당신은 다른 것들을 가질 수 있습니다. 이 두 가지가 아닌 다른 이름을 사용하십시오. 당신이 얻을 수있는 컨트롤의의 OnLoad에
// Get the container form.
form = this.FindForm();
// Simulate a click on the validation button
// when the ENTER key is pressed from the container form.
form.AcceptButton = this.cmdValider;
// Simulate a click on the cancel button
// when the ESC key is pressed from the container form.
form.CancelButton = this.cmdAnnulerEffacer;
: 여기 – Arthur