01-30-2020 04:00 PM
I am trying to make a selection-sensitive right-click menu for a string control. The user can fill it with text, then highlight some of it, right click, and do stuff to the text.
I have the shortcut menu working, but when you highlight text and right-click the shortcut menu, the selection highlight goes away. The selection *values* are still applied, but the visual indicator that you've selected text is gone. I'd like the text to remain highlighted while the run-time menu is displayed. In fact, even clicking outside of the control, then right-clicking back inside the control doesn't reset the "selection" field.
Is there an easy way to make the automatic selection highlight visible other than to manually apply a background color to the text?
See the attached .vi and .rtm for example code.
Solved! Go to Solution.
01-31-2020 01:16 AM
This is because when you right click, it has lost focus. So in the event handler, if you wire up a True to the property "KeyFocus" then it will show the highlighting again.
01-31-2020 10:02 AM
Ah, thanks Paul. That *mostly* works, but if you add it to the Shortcut Menu handler it will lose focus while the menu is up, then regain focus when the menu disappears. This means the highlight is gone while the menu is up.
To fix this, add a Shortcut Menu Activation? filter event and set the key focus there. Set Discard? to False. This way, the control gains key focus again immediately after losing it, and retains the highlight during the menu selection.
There is a small flicker of lost focus when you do this (I tried it with both Shortcut Menu Activation? and Mouse Down, same results). The flicker is very quick though and should be plenty for what I need, so thanks for the help!