How many lines of text are visible in the Editor?

  • WP Tools: 5.48.5, Delphi 5, Windows XP.

    Problem: Assume some text already exists in the WP Editor. Using a Combobox (or Macro expansion), user insert 10-20 lines of text near top (or bottom) of the editor. Depending on number of lines added, the new text may easily fit in the visible window OR part of it end up below bottom (thus TopOffSet should be adjusted) OR there are too many lines to fit (thus the question in this post.)

    Key Point: User needs to review/edit newly added text. Therefore, to the extent possible, new text needs to "stay" in the visible area of Editor.

    The obvious solution will be to know TopOffSet and current line number before text is added and calculate how many lines have been added so that TopOffset can be recalculated. I can figure that much. But to really position newly added text accurately, I also need to know: HOW MANY lines are visible in the editor.

    Note: There are NO tables or graphics in the document - just rich text.

    Question: How do I find out HOW MANY lines of text are visible in the editor?

    For example, I can visually count that in my current implementation, 30 lines of text are visible in editor. Needless to say, number of visible lines will change if editor window is resized or Font / Zoom are changed.

    As Always, thanks in advance.

    JayM

    • Offizieller Beitrag

    Hi,

    Using WPRichText1.ActivePar.Lines[0].Height; You can get the current height of one line of text. It will only help, if all lines are the same height.

    I would rather check the cursor position before and after the text insertion.

    GetYPositionTw will calculate the Y position in twips from the start of the page (you can subtract the header marging)

    WPRichText1.GetParXYBaselineScreen() using with ActiveParaghraph and ActivePosInPar as parameter will be more useful. You can scroll up, in case the Y is > height of the editor.