2009-04-17 5 views
0

Form 오브젝트의 OnKeyDown에 키 스트로크가 수신 중입니다. 몇 가지 조건이 충족되면 (예 : 키 입력이 인쇄 가능한 문자이고 단축키가 아닌 경우) 양식의 텍스트 컨트롤로 키를 전달하고 텍스트 컨트롤에 포커스를 설정하여 사용자가 계속 입력 할 수있게하려고합니다. MapVirtualKey을 사용하여 입력 한 문자를 디코딩 할 수는 있지만 "대문자"문자 (항상 대문자) 만 표시됩니다. ToUnicodeEx을 사용하면 너무 많은 PITA처럼 보입니다.WinForms의 다른 컨트롤로 키 스트로크 전달

가장 좋은 방법은 무엇입니까? 단순히 Windows 메시지 자체를 전달하는 방법이 없습니까?

ProcessKeyPreview 등을 가로 채거나 텍스트 컨트롤의 ProcessKeyPreview으로 전달할 수 없습니까? 비슷한 선상에있는 아이디어는 없습니까?

범프 : 답변 없음!

답변

1

나는 다음과 같은

private void MyFunkyForm_KeyDown(object sender, KeyEventArgs e) 
{ 
    // to avoid duplicate letters in textbox :-) 
    if (textBox2.Focused == false) 
    { 

     // get the char from the Keycode 
     char inputChar = (char)e.KeyCode; 
     if (char.IsLetterOrDigit(inputChar)) 
     { 
      // if letter or number then add it to the textbox 
      textBox2.Text += inputChar; 
     } 

     // set focus 
     textBox2.Focus(); 
     // set cursor to the end of text, no selection 
     textBox2.SelectionStart = textBox2.Text.Length; 
    } 
} 
단일 양식에 이런 짓을
관련 문제