Line and Column in RichTextBox 
Author Message
 Line and Column in RichTextBox

Hi!

Is it possible to get line and column numbers of the cursor position in a
RichTextBox control?

Jan Petter



Mon, 20 Oct 2003 20:26:16 GMT  
 Line and Column in RichTextBox
To get line number, starting from 0, of current cursor pos.:

CursorPos = RTB.selStart
LineNum = RTB.GetLineFromCharacter(CursorPos)

To get the column you can count back to the last vbcrlf
 or use EM_LineIndex   (const EM_LineIndex = &HBB )

StartChar = SendMessage(RTB.hwnd, EM_LINEINDEX, LineNum, 0)

column = CursorPos - StartChar
_________________________________

Quote:

>Hi!

>Is it possible to get line and column numbers of the cursor position in a
>RichTextBox control?

>Jan Petter



Mon, 20 Oct 2003 21:21:25 GMT  
 Line and Column in RichTextBox
Von den Thu, 3 May 2001 14:26:16 +0200, "Jan Petter Skarb?vik"

Quote:
> Hi!

> Is it possible to get line and column numbers of the cursor position in a
> RichTextBox control?

Not directly with p;ain old VB.  But you can access the
cursor's character position with RichText.SelStart.  
With this datum, you can find the row number by counting
the number of CRLF pairs which appear in the
RichTextBox *before* RichTextBox.SelStart.  To get the
column number, subtract RichTextBox.SelStart from the
character position of the beginning of the current line,
which will be one char past the latest CRLF.


:)      the Christian Privateer     :) Company: ppse.org
:)          aka Jack Voltz          :) Home page: ppse.org/me
:)   M  A  R  A  N  A  T  H  A  !   :) Prolife: ppse.org/prolife
:) S i e m p r e  P o r   V i d a ! :) Music: ppse.org/music
;)       Pour la Vie, toujours !    :)
;)         Sempre per la Vita!      :)  
;)          Semper Pro Vita!        :)
;)  A L W A Y S   P R O   L I F E ! :)



Tue, 21 Oct 2003 01:24:25 GMT  
 Line and Column in RichTextBox
Take a look at the methods detailed at http://www.mvps.org/vbnet/ in the
Text / String section. Most of the textbox methods apply to RTF's as well.

--

Randy Birch
MVP Visual Basic

http://www.mvps.org/vbnet/

Please respond only to the newsgroups so all can benefit.



: Hi!
:
: Is it possible to get line and column numbers of the cursor position in a
: RichTextBox control?
:
: Jan Petter
:
:



Tue, 21 Oct 2003 10:59:10 GMT  
 Line and Column in RichTextBox
The following, written for a normal TextBox but will also works with a
RichTextBox if the references are changed appropriately (TextBox to
RichTextBox).

Paste this code in the (General)(Declarations) section of your Form for
single form use; or remove the Private keyword and place it into a BAS
Module (Project/AddModule from VB menu bar) for project wide scope:

****************BEGIN  PASTE******************
Private Declare Function SendMessageLong Lib _
    "user32" Alias "SendMessageA" _
    (ByVal hwnd As Long, _
     ByVal wMsg As Long, _
     ByVal wParam As Long, _
     ByVal lParam As Long) As Long

Function CursorLine(TextBoxIn As TextBox) As Long
    CursorLine = SendMessageLong(TextBoxIn.hwnd, &HC9, -1&, 0&) + 1
End Function

Function CursorColumn(TextBoxIn As TextBox) As Integer
  CursorColumn = TextBoxIn.SelStart - _
                            SendMessageLong(TextBoxIn.hwnd, &HBB, -1, 0)
End Function
******************END  PASTE******************

Rick



Quote:
> Hi!

> Is it possible to get line and column numbers of the cursor position in a
> RichTextBox control?

> Jan Petter



Tue, 21 Oct 2003 14:54:57 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Scroll line by line in RichTextBox

2. MSHFlexGrid Columns (line) & TextBox lines

3. VB ListView Control - How to just display column lines - no row lines

4. Column format text in RichTextBox via sendmsg or??

5. Help: row/column pos in textbox/richtextbox control

6. Determining current column in RichTextBox

7. Returning the row and column position in a richtextbox

8. RichTextBox Line Numbers

9. Can't get richtextbox to scroll down to last line after update

10. Get last visible line of RichTextBox

11. Selecting a line of text from a RichTextBox

12. Jump to line in richtextbox

 

 
Powered by phpBB® Forum Software