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: 

Use GetCtrlAttribute function to check for Control Type

Solved!
Go to solution

Hi guys,

I've been planning to modify Label text size using "for" loops. To check for the type of control, I'm using GetCtrlAttribute.I tried to run but it shows an error. "The Attribute passed is not valid"

 

Code:

GetPanelAttribute(panelHandle, ATTR_NUM_CTRLS, &i_num_of_controls);
for ( i = 2; i <= i_num_of_controls ; i++ )
{
  // Transform the label attributes of the control.   
  if (GetCtrlAttribute (panelHandle, i, ATTR_LABEL_POINT_SIZE,&
i_org_text_size) >= 0 )

 {
    f_new_text_size =ceil( (float) i_org_text_size * 0.8);
    SetCtrlAttribute(panelHandle, i, ATTR_LABEL_POINT_SIZE, (int)f_new_text_size);
  }
}

Error :

sitirasip_0-1590977856528.png

This error is prompted because, the control id passed into the GetCtrlAttribute, is not a "Label" control id.

I can bypass the error by manually check which control id is a Label control and put the id number as one of the if condition. This is not what I want to apply right now.

 

Question:
1. So, does anyone know, how can I check for Label control without having to check manually by getting the label's id from header file? 

Thank you!

0 Kudos
Message 1 of 3
(1,749 Views)
Solution
Accepted by topic author sitirasip

Try using GetCtrlAttribute() to read ATTR_CTRL_STYLE.

Message 2 of 3
(1,708 Views)

Thanks Sporty . It works wonders!


My solution is , I listed out the ALL styles for control type and then apply code for only selected control type's style.

Here is my sample code :

sitirasip_0-1591158870344.png

sitirasip_1-1591159010172.png


Feel free to point out anything that I can do to enhance my code 😄
Thank you!

0 Kudos
Message 3 of 3
(1,667 Views)