02-28-2018 01:32 PM
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
Solved! Go to Solution.
02-28-2018 03:51 PM
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
03-08-2018 03:41 AM
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...
03-08-2018 07:15 AM - edited 03-08-2018 07:16 AM
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.
03-08-2018 10:36 AM
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...
03-09-2018 01:47 AM
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.
03-13-2018 09:14 AM
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
03-13-2018 10:13 AM
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.
03-13-2018 10:32 AM
As an alternative you may want to consider MakeColor function
03-13-2018 10:36 AM
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