10-23-2020 07:44 AM - edited 10-23-2020 07:47 AM
My challenge is to have a program where the user can move an object/control type, in this case a text message, to the left as well as to the right. To perform this, I have initialised two buttons "left" and "right". When the left button is clicked by the user, the text message moves to the left and vice versa. Hence, the control type is the text message "PANEL_TEXTMSG", and "panelHandle" is my panel.
I have generated the callback-functions for the left and right button. In the callback function for the "left button" I have inserted the code below, which will move the text-message to the left when the user clicks "left". Ok, so far so good...
```
*** in the left-button call-back function ***
case EVENT_COMMIT:
SetCtrlAttribute (panelHandle, PANEL_TEXTMSG, ATTR_LEFT, 1);
break;
´´´
HOWEVER, there is no control attribute (like ATTR_LEFT) for moving an object (the text message) to the right. Why isn't there a control attribute called ATTR_RIGHT? Seems illogical? Does anyone know how to solve my problem?
10-25-2020 07:32 PM
With the left and width attributes you have all that's needed to guarantee the correct right alignment, if you think to it:
left position = right limit - control width
10-26-2020 01:58 AM
I feel that this is a misunderstanding. ATTR_LEFT is not a control attribute for moving a control to the left but for the absolute (horizontal) position of the control with respect to the panel origin. A control value of 1 as in your example means that the left border of the control is offset one pixel from the panel offset. If you are interested in moving the control it might be a more general approach to first read its position using GetCtrlAttribute (....ATTR_LEFT, x_pos) and then either calculate x_pos = x_pos + distance for a movement to the right or x_pos = x_pos - distance for a movement to the left, and then calling SetCtrlAttribute (...ATTR_LEFT, x_pos).