문제

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