LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Text selection highlight disappears in string control when right-clicking

Solved!
Go to solution

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.

0 Kudos
Message 1 of 3
(2,539 Views)
Solution
Accepted by topic author BertMcMahan

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.

Message 2 of 3
(2,469 Views)

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!

0 Kudos
Message 3 of 3
(2,412 Views)