Applies To:
  • CitectSCADA

Summary:
A text object can display one or more lines of text separated by carriage returns. How can I center the text vertically, for example to center it inside a box, if the number of lines of text may change?

Solution:
There is no built-in option to set the vertical alignment of text like there is for horizontal alignment. However, the Vertical Movement properties can be used to move the text up and down as needed. You just need to find the number of lines of text and how many pixels to move.

  1. Place a text object on a graphics page and enter test text with the maximum number of lines to display.
  2. Optionally, draw a rectangle around the text so the text is centered in the rectangle.
  3. Measure the number of pixels from the top of one line of text to the top of the next line. You can find this by using the mouse coordinates shown in the status bar at the bottom of the window. Enable the Cross Hair Cursor in the View menu to make this easier.
     
  4. Open the text object's properties, Appearance (Display Value) tab and set the type to String.
  5. Enter the string variable tag name to display in the String Expression.
  6. Go to the Movement (Vertical) tab and set the Movement Expression to: StrLines(TagName)
  7. Select Specify Range. Set Minimum to 1 and set Maximum to the maximum number of lines of text.
  8. Set Offset At Minimum to 0.
  9. Calculate the value to enter for Offset At Maximum using: (Maximum number of lines - 1) / 2 * Line height in pixels
    For example, (4 lines of text - 1) / 2 * 16 pixels = 24
  10. Copy the attached Cicode file into your project. This contains the StrLines function.

Tips:

  • If the text moves left and right in the runtime instead of up and down, make sure you entered the movement expression in the vertical movement tab on the right side of the dialog, not horizontal movement.
  • If your text object displays several separate genie text values separated by newline characters (e.g. %Text1%^n%Text2%^n%Text3%) you do not need the Cicode function. Just set the movement expression to: (StrLength("%Text1%") > 0) + (StrLength("%Text2%") > 0) +
       (StrLength("%Text3%") > 0)

 


Keywords:
 

Attachments

String.ci