03-23-2011 02:55 PM - edited 03-23-2011 03:03 PM
I want to toggel the background color of text button. For ON white and OFF gray. How to change the background color of Text button? If I use the ATTR_TEXT_COLOR the color of the text changes but when I use ATTR_OFF_COLOR or ATTR_ON_COLOR it does not show any color change. I though maybe it was too fast so even added ProcessDrawEvent() but no sucess.
Here is the snippet:
int isSet = 0;
switch(event)
{
case EVENT_COMMIT;
}
And if I try ATTR_TEXT_BGCOLOR it gives run time error "the attribute passed is not valid". I am using Text button from Toggel group.
TIA.
03-23-2011 03:18 PM
So here is a little detail I missed.
The button should change its color based on the condition met, so for example if the button is in OFF position and the condition is met it should change its background color and condition can be met when button is in ON position. Is there any other attribute that can be used other that ATTR_ON_COLOR and ATTR_OFF_COLOR to avoid more logic check?
TIA
03-23-2011 03:23 PM - edited 03-23-2011 03:26 PM
Hi,
what do you mean by text button? Are you refering to a command button? If yes, you can use ATTR_CMD_BUTTON_COLOR
If you are referring to a toggle button, you can use ATTR_ON_COLOR
03-23-2011 06:27 PM
yes its a toggel button. Using the ATTR_ON_COLOR is not changing the button color?
03-24-2011 01:07 AM
It seems to me that your desire to change the color of the button is really a way of changing its state from on to off and viceversa.
A togglebutton is a special bi-state command: it can assume an off-state (button unpressed) or an on-state (button pressed), each with its own color. But if you have windows visual style enabled on the panel you cannot change those colours, as they are depending on screen theme set in the machine. You receive a warning if you attempt to do so in the UIR editor; apparently the command is simply ignored without error if done at runtime.
This attribute can be individually set at runtime for a specific control by using ATTR_DISABLE_PANEL_THEME attribute for that control: from this moment on it will honour the colours you set with ATTR_xxx_COLOUR attribute, however it will result ugly with respect to other controls in the panel.
03-24-2011 02:30 AM - edited 03-24-2011 02:32 AM
Please disregard the first sentence in my previous post as it is completely unrelated to what I understood is your problems. I forgot to delete it while completing the message!
03-24-2011 10:13 AM
lvrat:
You can also change the colors for the button states using the UI editor instead of doing it programmatically.
1. Select the paintbrush tool on the UI editor tool bar.
2. Right click on the button you want to change.
3. Select and left click the color you want. You'll see the color of the control change as you mouse-over the colors displayed after you right-click.
4. Select the edit tool (a dashed-line box) on the UI editor tool bar.
5. Double-click on the button you want to change.
6. Change the Initial State to the opposite of whatever it was, and click OK.
7. Repeat steps 1 through 3 for that state.
If you want to restore the initial Initial State, repeat steps 4 though 6. The control will assume its Initial State when you select the paintbrush tool, so you can only paint the Initial State. That's why you need to change the Initial State so you can paint the other state.
You can also unlock the panel and control colors in the UI editor.
1. Double click on a blank spot on the panel in the UI editor.
2. Click on Other Attributes.
3. In CVI 6.0, uncheck Conform to System Colors. In CVI 2010, uncheck both Conform System Colors and Use Windows Visual Style for Controls.
03-24-2011 12:53 PM
Thx all for suggestions. When I unchecked "Use windows visual Styles for controls" from Other attributes button show the color changed. One thing I can't understand is why isn't ATTR_TEXT_BGCOLOR returns run time error when used with toggel button? The attribute ATTR_TEXT_BGCOLOR is listed under all control types.
03-24-2011 01:44 PM - edited 03-24-2011 01:46 PM
When you select All control types in the Select Attribute Constant dialog, it means show all the attributes for all of the controls, whether or not they apply to the control in question. If you select Text Button as your control type, you'll see that ATTR_TEXT_BGCOLOR is not listed.
Also, if you go to CVI Help, on the Index tab, enter Text Button, and you'll see a help topic for Text Button Control Attributes. You won't see ATTR_TEXT_BGCOLOR there.
03-24-2011 02:59 PM
Also, setting that attribute on a text button does result in a run-time error. If you execute the following code in the interactive window, for example:
#include <userint.h>
static int panel, control;
panel = NewPanel (0, "panel", 100, 100, 400, 400);
control = NewCtrl (panel, CTRL_SQUARE_TEXT_BUTTON_LS, "text button", 100, 100);
SetCtrlAttribute (panel, control, ATTR_TEXT_BGCOLOR, VAL_RED);
you should see this error: