|
-
Dec 12th, 2001, 12:26 PM
#1
Thread Starter
PowerPoster
SelStart = The beggining of SelText
I Have an RTB and i have selected text i.e.
Seltext="DFGHJKIHLKJLKJ"
I want the cursor to go back to the begging of the seltext and leave the text selected.
So in other words Select "DFGHJKIHLKJLKJ" and move the cursor back in front of the "D".
This seltext can be anywhere in the richtextbox so it is variable.
THanks for the HELP!
-We have enough youth. How about a fountain of "Smart"?
-If you can read this, thank a teacher....and since it's in English, thank a soldier.

-
Dec 12th, 2001, 12:42 PM
#2
Hyperactive Member
This does not exactly do the job you want, but I still can't find the way the make it yht way you want it, so I'm posting it, maybe someone will find out...
VB Code:
Private Declare Function SendMessagePoint _
Lib "user32" Alias "SendMessageA" ( _
ByVal hWnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
ByRef lParam As POINTL) As Long
Private Type POINTL
x As Long
y As Long
End Type
Private Const EM_CHARFROMPOS = &HD7
Private Sub RichTextBox1_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
Dim p As POINTL
Dim nRetVal As Long
If (Button And vbLeftButton) = vbLeftButton Then
'Recalculate the position from Twips to Pixels
p.x = x \ Screen.TwipsPerPixelX
p.y = y \ Screen.TwipsPerPixelY
nRetVal = SendMessagePoint(RichTextBox1.hWnd, EM_CHARFROMPOS, 0, p)
nRetVal = nRetVal And &HFFFF&
[B]RichTextBox1.SelStart = nRetVal - RichTextBox1.SelLength[/B]
End If
End Sub
The bolded line should be the one to modify, but I can't figure out how!!!
Hope somebody will help you !
-
Dec 12th, 2001, 12:50 PM
#3
Thread Starter
PowerPoster
Hi, thanks for the help. But your right that doesnt work.
I didn't think this would require API. Surely there is a way just using the RTB methods to accomplish this.
-We have enough youth. How about a fountain of "Smart"?
-If you can read this, thank a teacher....and since it's in English, thank a soldier.

-
Dec 12th, 2001, 12:51 PM
#4
You could add your own sub or property procedure to do that.
VB Code:
Public Property Let SelText(ByVal str As String)
With RichTextBox1
.SelText = str
.SelStart = .SelStart - Len(str)
.SelLength = Len(str)
.SetFocus
End With
End Property
Now instead of calling RichTextBox1.SelText = "xyz" you call Me.SelText = "xyz"
Best regards
-
Dec 12th, 2001, 02:10 PM
#5
Thread Starter
PowerPoster
Hmm i didnt think this was so hard.
Is it possible to return the cursor to the begining of the selected text without deselecting the text?
Like i have "XYZ" selected. I need the cursor to go back to the "X" but leave the "XYZ" Still highlighted.
Is this not possible?
-We have enough youth. How about a fountain of "Smart"?
-If you can read this, thank a teacher....and since it's in English, thank a soldier.

-
Dec 12th, 2001, 06:54 PM
#6
Thread Starter
PowerPoster
-We have enough youth. How about a fountain of "Smart"?
-If you can read this, thank a teacher....and since it's in English, thank a soldier.

-
Dec 12th, 2001, 07:12 PM
#7
So Unbanned
Well
hmm...
you could possibly set a negative .SelLength.
Try it I guess.
-
Dec 12th, 2001, 07:13 PM
#8
Thread Starter
PowerPoster
-We have enough youth. How about a fountain of "Smart"?
-If you can read this, thank a teacher....and since it's in English, thank a soldier.

-
Dec 12th, 2001, 07:15 PM
#9
Fanatic Member
yes i was just going to suggest what about selecting it backwards starting at the end point and finishing at the start eg noramally to select the word "Hello" you would start at "H" and end at "o" instead start your selection at "o" and end at "h"
-
Dec 12th, 2001, 07:20 PM
#10
So Unbanned
Why is this so important?
-
Dec 12th, 2001, 07:22 PM
#11
Thread Starter
PowerPoster
Does it matter why it's so important? =p It's important cause I want to know it.
You can't Select text backwards. I have tried. I would be glad if someone could prove me wrong.
-We have enough youth. How about a fountain of "Smart"?
-If you can read this, thank a teacher....and since it's in English, thank a soldier.

-
Dec 12th, 2001, 07:23 PM
#12
So Unbanned
-
Dec 12th, 2001, 07:28 PM
#13
Thread Starter
PowerPoster
why would i need to? Did you read the thread?
-We have enough youth. How about a fountain of "Smart"?
-If you can read this, thank a teacher....and since it's in English, thank a soldier.

-
Dec 12th, 2001, 07:36 PM
#14
So Unbanned
Originally posted by Arc
Bumpage
Yes I did.
-
Dec 12th, 2001, 07:45 PM
#15
The SelStart and the SelLength property sends an EM_SETSEL message to the textbox or rtb.
With EM_SETSEL you specify the start position of the selection in wParam and the end position in lParam.
But according to MSDN Library:
The caret is placed at the end of the selection indicated by the greater of the two values nEnd and nStart.
So I suppose you can't do it through code but you could always play with the SetCaretPos API function if you like but I think (haven't tested it yet) that that would destroy any selection.
-
Dec 12th, 2001, 08:42 PM
#16
Thread Starter
PowerPoster
Damnit! This can't be impossible! I've never tried to do anything in VB that turned out to be impossible.
THere has to be Some way!
I have put waaaaaayyyy too much work into this project for this part to not work. If this doesnt work i might as well scrap the whole thing.
Hey Joacim. What i am trying to do is duplicate the way a listbox selects items. It highlights the text. BUt in a listbox it doesnt scroll off to the right when an item is selected. however in a RTB it does.
Can you think of anyway i can duplicate this process? ANything would be appreciated. At this point i am very depressed.
So any hope at all would be great!
-We have enough youth. How about a fountain of "Smart"?
-If you can read this, thank a teacher....and since it's in English, thank a soldier.

-
Dec 12th, 2001, 08:44 PM
#17
-
May 3rd, 2017, 10:34 PM
#18
Member
Re: SelStart = The beggining of SelText
Why not try Len() and Left$()?! It's something like :
Text1.text being a string
If Len(Text1.Text) = 14 Then
Text1.Text = Left$(Text1.Text, 1) & Text1.Text
End If
I never tried these code, but this might help to get you started...
Last edited by ramp10er; May 3rd, 2017 at 10:45 PM.
-
May 4th, 2017, 06:45 AM
#19
Re: SelStart = The beggining of SelText
Two things 1) this is over 16 years old. If they haven't gotten their answer by now, they'll never get it. 2) your code still doesn't do what was asked.
-tg
-
May 4th, 2017, 08:31 AM
#20
Re: SelStart = The beggining of SelText
My usual boring signature: Nothing
 
-
May 6th, 2017, 01:13 PM
#21
Lively Member
Re: SelStart = The beggining of SelText
I tried this:
Code:
rtb.Text = "Mary had a little lamb"
i = InStr(rtb.Text, "little")
rtb.SelStart = i - 1
rtb.SelLength = 6
Debug.Print rtb.SelStart & " " & rtb.SelText
Debug printed 11 little is that what you're looking for?
-
May 6th, 2017, 05:10 PM
#22
Re: SelStart = The beggining of SelText
K---
Did you even READ posts 19 & 20?
-
May 6th, 2017, 05:18 PM
#23
Lively Member
Re: SelStart = The beggining of SelText
Yes, as a matter of fact I did. Why do you ask?
-
May 8th, 2017, 08:52 AM
#24
Re: SelStart = The beggining of SelText
Because you're replying to a person who asked the question sixteen years back and hasn't been active on the forum for about four years. The odds that they are still interested in the question are pretty slim. The odds that they are still using the language aren't that good, either. And finally, the answer you gave seems to miss the point of the question. Selecting part of the text is easy. Selecting part of the text, leaving it selected, AND putting the cursor elsewhere is what wasn't so easy.
My usual boring signature: Nothing
 
-
May 8th, 2017, 09:15 AM
#25
Lively Member
Re: SelStart = The beggining of SelText
Needless to say, I disagree with all points. First, as this board apparently has no Statute of Limitations, a fourteen year old threads remain active, it did/does not seem out of line to post a reply. Quite possibly the message originator has fallen from his perch a long time ago, but as evidenced by your responses, the posting has not gone unread (the object of the exercise). Lastly, the original message is explicit and states the selStart is to be moved to the front of the selText. Not at some unspecified position.
Notwithstanding the above, I bow to the censure of a 'super moderator',
Bob.
-
May 8th, 2017, 09:25 AM
#26
Re: SelStart = The beggining of SelText
True, there is no expiration on an open thread. However, there is an expiration on the utility of an answer to an open thread, and there is one, possible, side effect to replying to such an ancient thread. Frankly, I kind of think it might be beneficial, so I'm pretty ambivalent about it. The side effect is due to the fact that you can subscribe to a thread, in which case you'll get an email notice about a reply to the thread. So, the side effect is that a reply could, 'raise the dead'. That may annoy people, or it may bring back those who have wandered off. I know of cases where both results have occurred, which is why I'm ambivalent about such a post.
As to the code, where's the cursor after you run that?
My usual boring signature: Nothing
 
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
|