클래스를 만드는 폼이 있습니다. 이 클래스는 폼에서 실행되는 이벤트를 처리합니다. 문제는 KeyDown 이벤트를 사용하려고하지만 폼에 단추가 있고 KeyDown을 캡처하기 때문에 작동하지 않습니다. 다른 게시물에 대한 해결책은 ProcessCmdKey를 재정의하는 것이 었습니다. 문제는 다른 클래스 내부에서 메서드를 재정의하는 방법을 모르겠다는 것입니다. 아무도 내 다른 클래스 내부에서 모든 KeyDown 이벤트를 캡처 할 수있는 방법을 말해 줄 수 있습니까?다른 클래스의 KeyDown을 무시합니다. C#
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if (keyData == Keys.Left)
{
MoveLeft(); DrawGame(); DoWhatever();
return true; //for the active control to see the keypress, return false
}
else if (keyData == Keys.Right)
{
MoveRight(); DrawGame(); DoWhatever();
return true; //for the active control to see the keypress, return false
}
else if (keyData == Keys.Up)
{
MoveUp(); DrawGame(); DoWhatever();
return true; //for the active control to see the keypress, return false
}
else if (keyData == Keys.Down)
{
MoveDown(); DrawGame(); DoWhatever();
return true; //for the active control to see the keypress, return false
}
else
return base.ProcessCmdKey(ref msg, keyData);
}
"다른 클래스의 오버라이드 ..."는 의미가 없습니다. 맞습니까? –