问题
I'm having multiple windows throughout my 4gl program where I have to position to the center of the screen. For example:
OPEN WINDOW w_yesno AT 10, 10
WITH 4 ROWS, 56 COLUMNS
ATTRIBUTE (BORDER, MESSAGE LINE FIRST+1,
PROMPT LINE FIRST+2)
Is there any keyword I can use to automatically open it in the center? Something like:
OPEN WINDOW w_yesno AT CENTER
回答1:
No, there isn't a keyword solution to centring windows. You can use variables for the positions and do the calculation, or you can do the calculation a priori and use hard-coded positions as you've shown. If your window size is not 24x80, calculation is perhaps better.
In the dim distant past, I wrote some code where there were a variable number of windows down the screen, some of them with 2 lines, some with 3, some with 4 lines; then you have to position them all with calculations.
回答2:
I managed to center strings by calling the following function, passing in the string and number of columns.
FUNCTION center_string(str, cols)
DEFINE str CHAR(100),
cols, len, spcs SMALLINT
LET len = length(str)
LET spcs = (cols - len) / 2
IF len >= cols
THEN # Do nothing. Don't have enough columns to center this string
ELSE
LET str = spcs spaces, str
END IF
RETURN str
END FUNCTION
Then you can just call and return the centered string:
LET l_string = center_string(l_string, 54)
DISPLAY l_string
来源:https://stackoverflow.com/questions/27678553/positioning-a-4gl-window-in-center