을 클릭하십시오. 이제 C#을 배울 수 있도록 Tic-Tac-Toe 게임을 진행 중입니다. 약간의 기능을 추가하려고합니다. 사람들이 컴퓨터에서 NumPad를 사용하여 단추를 클릭하여 시뮬레이션 할 수있게하려고합니다.Keypress A 버튼을 시뮬레이션하려면 C#
여기에있는 내용이 있지만 NumPad를 사용하면 단추가 클릭되지 않습니다. 왜 그 이유를 알 수 있습니까?
//===============================
// start NumPad Simulate Clicks
// NumPad MyButtons
// 7 8 9 1 2 3
// 4 5 6 4 5 6
// 1 2 3 7 8 9
//===============================
public void myControl_NumPad7(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)Keys.NumPad7)
{
button1_Click(null, null);
}
}
public void myControl_NumPad8(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)Keys.NumPad8)
{
button2_Click(null, null);
}
}
public void myControl_NumPad9(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)Keys.NumPad9)
{
button3_Click(null, null);
}
}
public void myControl_NumPad4(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)Keys.NumPad4)
{
button4_Click(null, null);
}
}
public void myControl_NumPad5(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)Keys.NumPad5)
{
button5_Click(null, null);
}
}
public void myControl_NumPad6(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)Keys.NumPad6)
{
button6_Click(null, null);
}
}
public void myControl_NumPad1(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)Keys.NumPad1)
{
button7_Click(null, null);
}
}
public void myControl_NumPad2(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)Keys.NumPad2)
{
button8_Click(null, null);
}
}
public void myControl_NumPad3(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)Keys.NumPad3)
{
button9_Click(null, null);
}
}
이것은 내가 찾고있는 것으로 보이지만 코드를 어디에 둘 것인지 파악할 수 없습니다. 나는 KeyPreview = true를 설정했다. Form1이 초기화 된 후 초기화됩니다. – Cistoran
폼의 속성 (속성 창)에 설정하면됩니다. 속성 창에서보기를 이벤트 섹션으로 변경하고 KeyDown 이벤트를 찾아 해당 항목을 두 번 클릭합니다. 이렇게하면 코드에 Form_KeyDown 이벤트가 추가되어 코드를 삽입 할 수 있습니다. 또는 양식의 소스 코드로 이동하여 "override"를 입력하십시오 - Code Insight 창에서 "OnKeyDown"메소드를 선택하십시오. 스텁이 생성됩니다. "base.OnKeyDown"줄 다음에 코드를 추가하십시오. –
방금 시도했지만 아직 작동하지 않는 것 같습니다. 나는 : with :를 대체 할 때부터 몇 가지 오류가 줄어들었다. 주요한 것들. 중단 또는 계속할 봉쇄 루프가 없습니다 (이들은 break와 같습니다) 할당, 호출, 증가, 감소 및 새 오브젝트 표현식 만이 명령문으로 사용될 수 있습니다. (x3) (Keys.NumPad와 스위치 닫는 대괄호에서이 문제가 발생 함 – Cistoran