-
January 3rd, 2007, 06:43 AM
#1
[RESOLVED] RichtextBox
Dear All,
Is there any method avaliable to get text of the present cursor postion in a richtext box.
-
January 3rd, 2007, 09:27 AM
#2
Re: RichtextBox
Yes. The present cursor position is the .SelStart property.
If you set the .SelLength property to say 5, you can access these 5 characters after .SelStart in the .SelText property.
The .SelText property is always equal to the text beginning at .SelStart having .SelLength characters. If the rtb would get the focus, this text would be marked.
-
January 3rd, 2007, 11:06 PM
#3
Re: RichtextBox
Dear WOF,
I want to simply get the entire word at the current cursor location.
-
January 3rd, 2007, 11:37 PM
#4
Re: RichtextBox
You can use the .Find property to search for the first blank after .SelStart, or whichever character you need.
-
January 3rd, 2007, 11:44 PM
#5
Re: RichtextBox
Can you pls exaplain with an example.
-
January 4th, 2007, 12:23 AM
#6
Re: RichtextBox
Try this out. It finds and bolds words.
Code:
Option Explicit
Private Sub Form_Load()
Dim a%, b%, q%
With rtb
.Text = "In process reject rate for Department 1 : 4.34 %" & vbCrLf & _
"In process reject rate for Department 1 : 124.34 %" & vbCrLf
q = .Find(":") - 1
Do While q > 0
a = .Find(":", q)
b = .Find(vbCrLf, a)
.SelStart = a + 1
.SelLength = b - a + 1
.SelBold = True
q = .Find(":", b + 1)
Loop
.SelStart = 0
End With
End Sub
-
January 4th, 2007, 01:17 AM
#7
Re: RichtextBox
or you can use the SendMessage. just search the msdn for EM_FINDWORDBREAK (WB_MOVEWORDLEFT, WB_RIGHTBREAK, etc..) for info.
Busy
-
January 4th, 2007, 01:44 AM
#8
Re: RichtextBox
Dear Thread,
I am new to Sendmessage,Can you please give one example?
-
January 4th, 2007, 10:01 PM
#9
Re: RichtextBox
actually, plenty of sample codes can be found here in the forum. i think what you need is the actual code (just kidding though ) ..
it requires a richtextbox (rtb) and a command button (command1).
Code:
Option Explicit
Private Const WM_USER As Long = &H400
Private Const EM_FINDWORDBREAK As Long = (WM_USER + 76)
Private Const WB_MOVEWORDLEFT As Long = 4
Private Const WB_MOVEWORDRIGHT As Long = 5
Private Const WB_RIGHTBREAK As Long = 7
Private Const EM_SETSEL As Long = &HB1
Private Const WB_CLASSIFY As Long = 3
Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByRef lParam As Any) As Long
Private Sub Command1_Click()
Dim i1&, i2&, i3&
If SendMessage(rtb.hwnd, EM_FINDWORDBREAK, WB_CLASSIFY, ByVal rtb.SelStart) = 0 Then
' det word boundary (left and right position)
i1 = SendMessage(rtb.hwnd, EM_FINDWORDBREAK, WB_MOVEWORDLEFT, ByVal rtb.SelStart + 1)
i2 = SendMessage(rtb.hwnd, EM_FINDWORDBREAK, WB_RIGHTBREAK, ByVal i1 + 1)
i3 = SendMessage(rtb.hwnd, EM_FINDWORDBREAK, WB_MOVEWORDRIGHT, ByVal i1 + 1)
If i2 > i3 Then i2 = i3
' select word
SendMessage rtb.hwnd, EM_SETSEL, i1, ByVal i2
' display word
MsgBox rtb.SelText
Else
MsgBox "Cursor is not pointing to a word/char."
End If
End Sub
hope it helps!
Busy
-
January 5th, 2007, 12:13 PM
#10
Re: RichtextBox
That's a good one, Thread1. What does the WB_CLASSIFY call actually do?
Isn't there somewhere a good tutorial or summary about the SendMessage usage? It seems there is such a lot of messages you can send. That's such an enormous amount of possibilities I can't use because I don't know them.
-
January 8th, 2007, 05:30 AM
#11
Re: RichtextBox
Good Code.Works Like a Charm .
Warm Welcome to Thread1,
Danasegar
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
|