Skype:TextControlSupport
Orders:877-462-4772
TX Text Control - word processing components.
What is this?Syndicate this content

Scrolling in TX Text Control- Part II

This source code snippet requires TX Text Control ActiveX
Author:TX Text Control Support Department
Language:Visual Basic
Version:1.1
Released:March 20, 2001
Last modified:January 11, 2008
Requirements:TX Text Control ActiveX with Visual Basic
Download code:scrolling_part2.zip Download [5.45 KB, ZIP]

This week we will continue with our article about scrolling in a search context. Last week's edition is archieved here.

What we have now is usable, but we can still improve upon it.

Currently, when we are stepping through the found results we use TX Text Control's built-in search feature to highlight the found word. But if we do the scrolling manually, we can move the highlight right to the top line on the screen; thus the user can easily see what has been highlighted.

Here is how it works. We have simply removed the HideSelection calls from the Load and Unload handlers so TX Text Control does not interfere with our custom scrolling. Then after the selection has been set in the Button handlers, the Sub MovePosToFirstLine is called given the input position of the selection as a parameter.

Here is the VB code:

  1. Private Sub MovePosToFirstLine(nPos As Long)
  2.  
  3. Dim lResult As Long, lr As LineRect
  4.  
  5. ' Get the absolute line number of the position
  6. lResult = SendMessage2(Form1.TXTextControl1.hwnd, TX_LINEFROMCHAR, 0, nPos)
  7.  
  8. If lResult = 0 Then
  9. Exit Sub
  10. End If
  11.  
  12. lr.lLineIndex = lResult - 1
  13.  
  14. ' Now query the offset of this line
  15. lResult = SendMessage(Form1.TXTextControl1.hwnd, TX_GETLINERECT, 0, lr)
  16.  
  17. Form1.TXTextControl1.ScrollPosY = lResult
  18. End Sub

First of all, the absolute line that contains the given position is determined. This is done with the TX_LINEFROMCHAR message. If no error occurs, the result is assigned to the lLineIndex member of the LineRect structure. This structure is sent to TX Text Control via the TX_GETLINERECT message which returns the offset of the line in twips to the very top of the page. This value is the value needed for the ScrollPosY method to scroll right to the found line.

The only tricky thing is the use of the SendMessage API call, but as a Windows user, you should at least have heard of it. In the next version of TX Text Control it will not be necessary to use SendMessage here, because TX 9.0 will come up with a bunch of new methods.

This tip can be used in other cases, as well. For example, if you want to be able to scroll to a given chapter in your application and you have marked the beginning of the chapter with a field, then you scroll right to that chapter by supplying the FieldStart value to the MovePosToFirstLine sub.

top

Top 10 Bestselling Product Award 2007Top 25 Publisher Product Award 2007Top 10 Bestselling Product Award 2007 in JapanTop 25 Bestselling Product Award 2006Top 25 Bestselling Publisher Award 2006Reader's Choice Award, dot.net magazin, 3rd place