vcl combobox doesn't always show that it has focus

后端 未结 2 1346
闹比i
闹比i 2021-01-27 01:05

When I tab from another control to a combo box it shows the box with a dotted line around the text, but when I set the control to be active programmatically, it doesn\'t show th

相关标签:
2条回答
  • 2021-01-27 01:16

    This is by design of the operating system, prevents clutter on the screen when a user is not using the keyboard. Here is a thorough explanation of the reasons. And here is an explanation of how the mechanism works.

    You can send a WM_UPDATEUISTATE to change the state of a window (and its child windows as per the documentation).

    ComboBox1.Perform(WM_UPDATEUISTATE, MakeWParam(UIS_CLEAR, UISF_HIDEFOCUS), 0);
    

    Above will update the UI state of the combobox as if keyboard cues are required.

    You don't have to send the message at focus switch time, you can send it at form creation for instance. You can also choose to send the message to the parent form, for all the controls to behave consistently, and can include UISF_HIDEACCEL in the high-word of WParam to also show accelerator characters underlined.

    Note that users already can choose to display keyboard indicators at all times system-wise. In Windows 7, the setting is at "Control Panel", "Ease of Access Center", "Make the keyboard easier to use", "Make it easier to use keyboard shortcuts", "Underline keyboard shortcuts and access keys".

    0 讨论(0)
  • 2021-01-27 01:34

    To make the focus rectangle appear on a combo box, when setting the focus programmatically, you can use the following code:

    ComboBox.SetFocus; 
    ComboBox.Perform(WM_SYSKEYDOWN, VK_TAB, 0); 
    
    0 讨论(0)
提交回复
热议问题