LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

GetCtrlBoundingRect returns wrong values after programatically changing the control size

I want to center a control (e.g. numeric thermometer) on a decoration and therefore use GetCtrlBoundingRect(...) to calculate the control position. If the control is higher than the decoration i adjust its height. After Setting the new height I call again GetCtrlBoundingRect(...) to calculate the coordinates to center it, but in the second call the function returns a value for the rect height that is much higher than the real control rect height.
Has anybody encountered the same problems and knows a solution?

Here is a code exmaple:
I wrote a small test program, which consists only of following lines concerning the control.
The control in the example is a numeric
thermometer with no title, visible digital display and an original height of about 250.

GetCtrlBoundingRect(panel, control, &top, &left, &height, &widht);
// returns height = 220
SetCtrlAttribute(panel, control, ATTR_HEIGHT, 50);

GetCtrlBoundingRect(panel, control, &top, &left, &height, &widht);
// returns height = 220 or slight smaller value


While trying around I found that the following code example seems to return the correct value in the second call to GetCtrlBoundingRect.

GetCtrlBoundingRect(panel, control, &top, &left, &height, &widht);
// returns height = 220
SetCtrlAttribute(panel, control, ATTR_HEIGHT, 50);
SetCtrlAttribute(panel, control, ATTR_HEIGHT, 50);
GetCtrlBoundingRect(panel, control, &top, &left, &height, &widht);
// returns height = 80
0 Kudos
Message 1 of 3
(3,074 Views)
If you are setting an attribute value of a control with SetCtrlAttribute, the new value will not be set until you finish the current callback function and process the redraw events. The reason for this is because you may want to change multiple attributes of a control without redrawing the UI for every SetCtrlAttribute call. If you want to process a SetCtrlAttribute immediately in the same callback function, you need to insert a ProcessDrawEvents() or ProcessSystemEvents() function call. For example, your code would change to:

GetCtrlBoundingRect(panel, control, &top, &left, &height, &width);
SetCtrlAttribute(panel, control, ATTR_HEIGHT, 50);
ProcessDrawEvents();
GetCtrlBoundingRect(panel, control, &top, &left, &height, &width);


Try this and see if it fixes y
our problem.

Best Regards,

Chris Matthews
Measurement Studio Support Manager
0 Kudos
Message 2 of 3
(3,074 Views)
I tried ProcessDrawEvents() and ProcessSystemEvents(), but it did not fix my problem. But I found out another strange behaviour: When I change the fill type of the control from "Fill below" to "Fill above" or "No fill" it works properly. Only with the fill type "Fill below" the problem occurs.

I attached my small test project to this comment

Regards,
Stefan Urich
0 Kudos
Message 3 of 3
(3,074 Views)