Вопрос

I have a toolstrip dropdownbutton which contains textbox in the dropdown menu. I'm trying to make it fire Validate event properly when an Enter key is pressed.

I have this simple code:

    private void txtSourceUrl_KeyPress(object sender, KeyPressEventArgs e)
    {
        if (e.KeyChar == Convert.ToChar(Keys.Enter))
        {
            txtSourceUrl_Validated(null, null);
        }
    }

Which works, But, it still makes the Windows sound for "improper input" (that "ding!") play, which is unfortunate. I don't know how to get rid of it, or how to do it properly, as this method I'm using seems to be kind of a hack.

I searched the text box properties, but there seems to be nothing related in there (AcceptsReturn doesn't work as text boxes in the dropdown can't be multiline). Any ideas?

Это было полезно?

Решение

Try setting e.Handled = true in the event handler.

UPDATE

To avoid confusion, this answers the question how to get rid of the sound on Enter. Answers to combo box not validating confirm the general approach and give another idea.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top