2017-09-11 1 views
-1

은 내가 TextBox을 만들어 나는 textbox1richtextbox1의 문자열이 동일한 경우 확인 에게 공간 바인딩 : textbox1키보드 키의 기본 기능을 중지하는 방법은 무엇입니까?

하지 쓰기 공간에 내가 를 누를 때 공간

if (e.KeyCode == Keys.Space) 
{ 
    if (richTextBox1.Text.Contains(textBox1.Text)) 
    { 
     richTextBox1.Text = richTextBox1.Text.Replace(textBox1.Text + " ", ""); 
     wpm++; 
     textBox1.Text = ""; 
    } 
} 

그래서 내가 원하는

+2

에서 적응이 답변 코드에 문제가? 질문 있습니까? –

+0

이 코드는 아니지만 어떻게 할 수 있는지 알고 싶습니다. –

+0

e.SuppressKeyPress = true; –

답변

0

은 MSDN 예를 here

// Boolean flag used to determine when a character other than a space is entered 
private bool spaceEntered = false; 

// Handle the KeyDown event to determine the type of character entered into the control. 
private void textBox1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e) 
{ 
    spaceEntered = e.KeyCode == Keys.Space; 
} 

// This event occurs after the KeyDown event and can be used to prevent 
// characters from entering the control. 
private void textBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) 
{ 
    // Check for the flag being set in the KeyDown event. 
    if (spaceEntered == true) 
    { 
     // Stop the character from being entered into the control since 
     e.Handled = true; 
    } 
} 
관련 문제