ComboBox carriage return must trigger the commit event

Source: Internet
Author: User
Regardless of whether the Drop-down list is expanded, a carriage return must trigger a commit event, and ESC must trigger the cancellation event, resulting in unintended results.
MSDN contains:
Combobox.isinputkey method
protected override bool isInputKey (
Keys KeyData
)
The isInputKey method returns True if the KeyData parameter contains a return or Escape value and the Droppeddown property is true.
Logically, when a drop-down list expands, a carriage return does not trigger a commit event, and ESC does not trigger a cancellation event, but that is not the case.

Test code:
public class Comboboxex:combobox {
    protected override bool isInputKey (Keys keyData)
    {
        if (droppeddown)
            switch (keyData) {case
                Keys.Return:return true;
                Case Keys.Escape:return true;
            }
        Return base. isInputKey (KeyData);
    }
You can see through the debugger that when the Drop-down list is not open, Droppeddown is false, isInputKey () executes it again, and behaves as expected. When the Drop-down list is open, the isInputKey () executes strangely two times, the first time Droppeddown is true, and the second droppeddown is false, causing isinputkey () to be fictitious, resulting in unintended results.

Solution:
public class Comboboxex:combobox {
    protected bool Droppeddownbak = FALSE;
    protected override bool isInputKey (Keys keyData)
    {
        if (Droppeddown | | Droppeddownbak) {
            if (Droppeddownbak) Droppeddownbak = false;
            if (droppeddown) Droppeddownbak = true;
            Switch (keyData) {case
                Keys.Return:return true;
                Case Keys.Escape:return true;
            }
        }
        Return base. isInputKey (KeyData);
    }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.