Muhammad Shehzad
Muhammad Shehzad

Reputation: 87

In winforms, on keydown event handler textbox event keypress is not working

In winform application, I am using a key down event to proceed to next field. It works properly but i want to handle an event of text box here as well like key press. If key down event on the form is available then key press event is not fired. How can i resolve it.

Any suggestions?

Upvotes: 1

Views: 2801

Answers (1)

Steve
Steve

Reputation: 216243

Every KeyDown event receive a KeyEventArgs parameter.
Inside the KeyEventArgs parameter there is a property named SuppressKeyPress.
According to MSDN setting this property to true avoid the KeyPress event
If you set this property to false, the current control with focus will receive the keypress.

private void formMain_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
    // Do your processing
    ....
    e.Handled = true;
    e.SuppressKeyPress = false;
}

Upvotes: 1

Related Questions