LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Toggle button background color?

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;

 

            GetCtrlVal( panel, control, &isSet );
           
            if(isSet)
            {
                 
                SetCtrlAttribute (panelHandle, PANEL_TOGGLEBUTTON, ATTR_ON_COLOR,
                                  VAL_RED);  
            }
            else
            {
                ProcessDrawEvents ();
                   
                SetCtrlAttribute (panelHandle, PANEL_TOGGLEBUTTON, ATTR_OFF_COLOR,
                                  VAL_DK_BLUE);
            }

 

}

 

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.

 

 

*************************************************
CLD
*************************************************
0 Kudos
Message 1 of 12
(6,241 Views)

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 

*************************************************
CLD
*************************************************
0 Kudos
Message 2 of 12
(6,237 Views)

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

Message 3 of 12
(6,237 Views)

yes its a toggel button. Using the ATTR_ON_COLOR is not changing the button color? 

*************************************************
CLD
*************************************************
0 Kudos
Message 4 of 12
(6,229 Views)

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.



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 5 of 12
(6,223 Views)

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!



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 12
(6,215 Views)

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.

 

Message 7 of 12
(6,204 Views)

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.

 

*************************************************
CLD
*************************************************
0 Kudos
Message 8 of 12
(6,195 Views)

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.

0 Kudos
Message 9 of 12
(6,189 Views)

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:

 

textcolor.png

 

 

0 Kudos
Message 10 of 12
(6,180 Views)