LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How to programatically change the background of a substring in a text box

I would like to programatically select a substring (such as a single word, or phrese) within a character buffer displayed in a CVI text box, and change the background color (in other workds, highlight the word). Similar to the highlighting that would be seen if a word was double clicked on within a text box.
Thanks in advance
0 Kudos
Message 1 of 6
(3,927 Views)
I am not sure an easy to do this using textbox. I use listbox or table for this type of application.
If you use table, just creat one column and add row just like textbox. And then you can use settablecellattr to change color.

Sheetal
Thanks.
CVI 2010
LabVIEW 2011 SP1
Vision Builder AI 2011 SP1
0 Kudos
Message 2 of 6
(3,927 Views)
You can use SetCtrlAttribute to select text with ATTR_TEXT_SELECTION_START and ATTR_TEXT_SELECTION_LENGTH. The text will then be highlighted when (and only when) the text box is the active control.

SetCtrlAttribute (panelHandle, PANEL_TEXTBOX, ATTR_TEXT_SELECTION_START, selectionStart);
SetCtrlAttribute (panelHandle, PANEL_TEXTBOX, ATTR_TEXT_SELECTION_LENGTH, selectionLength);
SetActiveCtrl (panelHandle, PANEL_TEXTBOX);

Look at the attached sample project.
Message 3 of 6
(3,926 Views)
Al S,

Thanks, this was a good start. Is this also applicable to textboxes with more than one line? I could find no attributes to set a particular target line. For example, in the attached .bmp, I searched for the word "Capacitor" in the third line. But because I could not select the line number to apply the attributes ATTR_TEXT_SELECTION_START & ATTR_TEXT_SELECTION_LENGTH - "tal (DRAC" is highlighted on the top line instead. Thanks
0 Kudos
Message 4 of 6
(3,926 Views)
It applies to text boxes with more than one line, but the ATTR_TEXT_SELECTION_START attribute counts total characters from the top of the box, not lines. If you want to select text starting at the fifth character on line 2, and there are 10 characters (including new-line) on line 1, then set ATTR_TEXT_SELECTION_START to 10+4=14 (START is 0 based).
0 Kudos
Message 5 of 6
(3,926 Views)
Al S.,
This will allow me to do what it is I was attempting. Before I received your suggestion, I wrote an app using some windows API calls to simulate mouse events such as double clicking on text, as a work around. Your solution looks looks a little cleaner.
Thanks,
0 Kudos
Message 6 of 6
(3,926 Views)