I have a .NET TextBox with AutoComplete feature on the form. The form has also AcceptButton and CancelButton defined. If I try to commit a suggestion with Enter key or close drop down with Esc, my form closes. How can I prevent this behavior?
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Carriage Return (ASCII chr 13) is missing from tex
- Generic Generics in Managed C++
- Why am I getting UnauthorizedAccessException on th
instead to Accept and Cancel buttons you can go for the following approach:
Handle the KeyDown event of the form, in the handler method you can have something similar to the below code
Another option is to derive your own custom TextBox class that performs validation when Enture/Return is pressed:
Simple way is to remove AcceptButton and CancelButton properties while you are in auto-complete textbox:
Do not assign AcceptButton and CancelButton form properties. Set DialogResult in the buttons OnClick event.