From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

color of text in a text box

Hi,

 

I need to write to a TEXT BOX a line of text is a specific color.

 

I can change ALL text but not just one line that has been written

SetCtrlAttribute (panelHandle, PANEL_ResultsBox, ATTR_TEXT_COLOR, VAL_GREEN);//Line Green

 

Each line I write will have a different color from the last so when finished the sequence of test each line written to the text box could have a different color.

 

The list will be reviewed some time later to check the status as defined by the color!!

 

Is this possible and if yes how?

 

Thanks for the help

Simon

0 Kudos
Message 1 of 7
(7,112 Views)
I suggest you switch from a textbox to a listbox or a table: in both controls color and some attributes of individual cells / rows can be customized so that you can give a colour evidence to your results.
 
In case of a listbox, you must prepare a string with appropriate embedded characters to add foreground and background colors (a reference help can be found in the online help for this control), while in case of a table you must apply the correct attribute to individual cells / rows after the text has been written.
 
This is an example of how to write a line in blue in a listbox:
   sprintf (item, "\033fg%06XThis text is written in blue", item, VAL_BLUE);
   InsertListItem (panelH, listbox, -1, li, ++line);

On a table, the same will be accomplished with:
   SetTableCellVal (panelH, table, MakePoint (1, 1), "Your text");
   SetTableRowAttribute (panelH, table, 1, ATTR_TEXT_COLOR, VAL_BLUE);

 
The table control gives you more flexibility in defining the default aspect of individual cells, but it's a little more difficult to manage if you have to dynamically add lines of data (use InsertTableRows before writing to the table). You can add a line to a listbox with a simple InsertListItem, on the other side organizing output in columns and so is a little more complicated than with tables. Since you must add several lines of results to your control, in my opinion a listbox is easier to manage.

Message Edited by Roberto Bozzolo on 01-26-2006 05:39 PM



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 7
(7,105 Views)

Hi,

 

And I thought list boxes were difficult but I am coming to grips with them.

 

GetValueFromIndex (panelHandle, PANEL_LISTBOX, count, &value);

GetLabelFromIndex (panelHandle, PANEL_LISTBOX, count, label);

sprintf (item, "\033fg%06X%s",VAL_RED,label);

InsertListItem (panelHandle, PANEL_ResultsDebugListBox, -1, item, ++line);

CheckListItem (panelHandle, PANEL_LISTBOX, count, 0);

 

In one list box (LISTBOX) I use for the selection while the second (ResultsDebugListBox) will report the result of the test, colour coded.

 

Now my problem is to clear at once all the selected items from LISTBOX.

 

At the moment if items are checked on closing the list box they are still checked when the list box is re-opened at a later stage.

 

How do I ensure no item is checked the first and every other time the list box is open?

 

Thanks for the help

Simon

0 Kudos
Message 3 of 7
(7,082 Views)

There is no mean of clearing items from a listbox depending on the checkmark: you must iterate the list items and delete them one by one.

GetNumListItems (panelHandle, PANEL_LISTBOX, &lines);

for (i = 0; i < lines, i++) {

   IsListItemChecked (panelHandle, PANEL_LISTBOX, i, &checked);

   if (checked) {

      DeleteListItem (panelHandle, PANEL_LISTBOX, i, 1);

      lines--;

   }

}

But, couldn't you delete them in the same moment in which you are transferring from one list to the second?



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 4 of 7
(7,076 Views)

Hi,

 

for (i = 0; i < lines; i++)

{

IsListItemChecked (panelHandle, PANEL_LISTBOX, i, &checked);

                        if (checked)

                                    {

                                    //DeleteListItem (panelHandle, PANEL_LISTBOX, i, 1);

                                    CheckListItem (panelHandle, PANEL_LISTBOX, i, 0);

                                    lines--;

                                    }

}

 

Changed one bit as it was not the line but just the tic beside the line needed removing.

 

Also I needed to add a blank line to the end of the list box, as the last tic was not been removed.

 

Is there any other way around this?

 

Thanks for the help

Simon

0 Kudos
Message 5 of 7
(7,069 Views)
Simon, if you're not deleting any line, the "lines--" instruction must be commented out too: this can be the reason for the last line not being examined by the for loop (really, the last "n" lines sould be skippend by the loop, being "n" the number of lines unchecked).


Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 6 of 7
(7,051 Views)

Thanks, I'll use a listebox

0 Kudos
Message 7 of 7
(4,111 Views)