|
-
May 6th, 2001, 03:10 AM
#1
RTFbox: get the cursor position..
thanks everyone who has helped me with RTXbox control.
I can now get the text line at the cursor using GETLINETEXT and GETLINEFROMCHAR
BUT how can I find where the cursor is in terms of the character position from the start of the current cursor text line?
.SelStart returns the position from the start of the text, NOT the start of the current line.
-
May 6th, 2001, 08:10 PM
#2
Using the old code I gave from your previous thread, you can use a textbox to get where the cursor is from the start of the current line.
Code:
Private Function GetLineText(rtb As RichTextBox, iLine As Integer)
Dim vArray As Variant
vArray = Split(rtb, vbCrLf)
GetLineText = vArray(iLine)
End Function
Private Sub RichTextBox1_Change()
Text1.Text = GetLineText(RichTextBox1, RichTextBox1.GetLineFromChar(RichTextBox1.SelStart) + 1)
Text1.Text = Mid$(Text1.Text, InStr(1, Text1.Text, Chr(32)))
Text1.SelStart = RichTextBox1.SelStart
Caption = Text1.SelStart
End Sub
-
May 7th, 2001, 02:12 AM
#3
Matthew:
what is the Text1 variable type? I am using a string or a label, but it dosn't have the .selstart property.
Can you explain how the RTF's .selstart (which = char position for start of file) be used to get char position from start of current line?
-
May 7th, 2001, 02:28 AM
#4
Matthew:
what is the Text1 variable type? I am using a string or a label, but it dosn't have the .selstart property.
Can you explain how the RTF's .selstart (which = char position for start of file) be used to get char position from start of current line?
-
May 7th, 2001, 06:26 AM
#5
Use the code above, and make the textbox invisible if you wish to use a Label instead.
-
May 7th, 2001, 09:19 AM
#6
Try this code:
Code:
Private Declare Function SendMessage _
Lib "user32" Alias "SendMessageA" ( _
ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
lParam As Any) As Long
Private Const EM_LINEINDEX = &HBB
Public Function GetColPos(rtb As RichTextBox)
Dim nPos As Long
nPos = SendMessage(rtb.hwnd, EM_LINEINDEX, -1, 0)
GetColPos = rtb.SelStart - nPos + 1
End Function
You can simply call the GetColPos in the SelChange event and assign the return value to a label or whatever:
Code:
Private Sub RichTextBox1_SelChange()
Label1.Caption = "Col position: " & GetColPos(RichTextBox1)
End Sub
Best regards
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|