How to disable the F4 key from displaying items in a ComboBox

You may not know this, but pressing the key F4on ComboBoxmakes it a drop-down list of items. I believe this is the default behavior on Windows.

Does anyone know how to override this behavior in WPF (C #)?

I know that overriding the default behavior is usually considered bad practice, however in this case I have a solid device with XP Embedded. It has several well-known function keys ( F1- F6) that should trigger different events. This works fine, however, if you focus on ComboBox, events do not fire when it crashes ComboBox.

I tried to catch the event KeyDownboth on the form and on ComboBoxlistening to the key F4, however this is not so far as the keystroke should be processed at a lower level.

Any ideas?

+3
source share
2 answers

I'm not sure about XP Embedded, but on a regular basis, this works. Use PreviewKeyDown and set e.Handled to true:

public MyWindowOrControl()
{
    InitializeComponent();
    cboTest.PreviewKeyDown += new KeyEventHandler(cboTest_PreviewKeyDown);
}

void cboTest_PreviewKeyDown(object sender, KeyEventArgs e)
{
    if (e.Key == Key.F4)
        e.Handled = true;
}
+3
source

You can create your own ComboBox class and just inherit from the old one. You hopefully can override keydown / up methods.

0
source

Source: https://habr.com/ru/post/1744197/


All Articles