Vertically center text selection

  • I need help with positioning selected text in a TWPRichText control. Basically my app needs to select a word in the document and then center the selection vertically in the control.

    Thanks for any help!

    Jim

  • This code seems to do what I'm looking for.

    Code
    // Determine Y coordinate of current cursor position
      // (WPRichText1.Height div 2) is the vertical center
      // Difference between these is how much to scroll TopOffset
    
    
      WPRichText1.GetParXYBaselineScreen( WPRichText1.ActiveParagraph, WPRichText1.ActivePosInPar, X, Y);
      WPRichText1.TopOffset := WPRichText1.TopOffset + (Y - (WPRichText1.Height div 2));