LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

how to change text of button during execution?

Solved!
Go to solution

hello everyone, i am new in labwindows... i will change the button background color, but it doesn't support, therefore i will change the text of the button during running the program. i have made a ring to choose which color, but it doesn't happen any change???!!! i have used:

GetCtrlVal (panelHandle, PANEL_RING, &color);
SetCtrlAttribute (panelHandle, PANEL_COMMANDBUTTON, ATTR_LABEL_COLOR, color);

the color has integer values from 0-18 for VAL_RED until VAL_LT_GRAY. when i choose a color and press the button, nothing is changed???!!! can anyone help me out? thanks

 

0 Kudos
Message 1 of 11
(5,070 Views)

VAL_RED, etc... are RGB colors NOT represented by an single integer, but as "R" "G" "B" values in 6-bytes.

VAL_RED would be 0xFF0000.

You would need to put these values in your ring control to set the correct color of the text on your command button.

userint.h gives the hex value of colors.  To use them in the ring control directly, convert to decimal, or programmatically link the ring integer to the defined constant.

 

Other than the correct format for colors, both of your commands will do what you want.

 

Hope this is clear.

TRS

0 Kudos
Message 2 of 11
(5,051 Views)

Unfortinately no... i tried with string as colors name like VAL_RED, it tells that it must be integer... i used converted codes to integer, but it doesnt like it... 

0 Kudos
Message 3 of 11
(5,016 Views)

It's not "strings as color names": VAL_RED is a macro that evaluates to an integer in compilation. Color name macros are defined in userint.h, where you can find for example:

#define VAL_RED                         0xFF0000L

So it must be used as follows:

SetCtrlAttribute (panelHandle, PANEL_COMMANDBUTTON, ATTR_LABEL_COLOR, VAL_RED);

 

You could also change the button color using ATTR_CMD_BUTTON_COLOR attribute, but whether it is honoured depends on other panel attributes. See the help for the attribute:

 

LabWindows/CVI ignores this attribute if you enable the ATTR_CONFORM_TO_SYSTEM_THEME attribute, enable the Use Windows Visual Styles for Controls option, or disable the ATTR_DISABLE_PANEL_THEME attribute.



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 11
(5,008 Views)

Hello roberto, no problem to change a text on a button in a loop, but to change a color is crazy... i have converted the hexadecimal values to integer, without any change... i will change the buttons color property, maybe it works... 

0 Kudos
Message 5 of 11
(5,003 Views)

Can you build up a small example of what you intend to do? I mean, not only the code but a complete project including the UIR and associated callbacks with only the functions where you find the problem.



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 11
(4,978 Views)

hello roberto and sorry i respond late... i have activated the custom color in the buttens property, but it only change the blue, when i choose other colors in a ring, it doesnt change the color, only dark color appears... my codes are: 

int CVICALLBACK part81 (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
int color, j;
short k[]={0xFF0000L, 0x00FF00L, 0x0000FFL, 0x00FFFFL, 0xFF00FFL, 0xFFFF00L, 0x800000L, 0x000080L,
0x008000L, 0x008080L, 0x800080L, 0x808000L, 0xC0C0C0L, 0x808080L, 0x000000L, 0xFFFFFFL,
0xA0A0A0L, 0xE0E0E0L};
switch (event)
{
case EVENT_COMMIT:
GetCtrlVal (panelHandle, PANEL_RING, &color);
j=(int)k[color-1];
SetCtrlAttribute (panelHandle, PANEL_COMMANDBUTTON, ATTR_CMD_BUTTON_COLOR, abs(j)); //it doesnt matter j or k the result is the same
break;
}
return 0;
}

 

i  really wanted to call the pallet color that choose a custom color, instead of ring, but i dont know how? appreciate if you look at and answer me, thanks

0 Kudos
Message 7 of 11
(4,943 Views)

If you want the user to choose a color you can place a color numeric on the panel and have him choose the color to use. Retrieve the value from the color numeric and pass it to your SetCtrlAttribute.



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 8 of 11
(4,938 Views)

As an alternative you may want to consider MakeColor function



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?
Message 9 of 11
(4,934 Views)
Solution
Accepted by topic author venusnajad56

Hi Venus,

 

I tried a code similar to yours and I noticed a similar issue when the ring only changes the button color to blue. Since short is 2 bytes, the colors that you are storing won't be correct. You want to change the short (2 byte) array to an int (4 byte) array to properly store the colors. Basically, do: 

 

int k[] = {0xFF0000L, ... } etc... 

 

Let me know what results you get!

 

Regards,

Vincent

Message 10 of 11
(4,932 Views)