VB6 RichTextBox SelStart Problem

Dear Experts,

In a VB6 RichTextbox, I need to obtain the current insert point (SelStart) with the MouseDown event. Although a standard textbox does this without a problem, the RichTextbox returns a 0 for the SelStart value on the first mouse click, then on each subsequent mouse click, it returns the previous click point. Strange, and not useful.

I have used a timer to obtain the actual SelStart point but this complicates things.

Is there a good way to obtain the actual SelStart/cursor position in a RichTextbox with the MouseDown event?

Thanks!
ttobin333Asked:
Who is Participating?
 
ttobin333Connect With a Mentor Author Commented:
Giving up on this...will use click event rather than mousedown. Thanks for the comments.
0
 
aikimarkCommented:
capture/save the selstart value in the mousemove() event for the RTF textbox.
0
 
hesCommented:
I just tested with this code and it returned the correct value each time I did a mouse down
Private Sub RichTextBox1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
MsgBox RichTextBox1.SelStart
End Sub
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
ttobin333Author Commented:
Aikimark: I will try the mousemove suggestion.

Hes:  the process you describe is what did not work for me. Please try again with some text in the RTB, clicking different locations.  When I do this, the 1st click gives me a value of 0, and the next click gives me the value of the 1st click.

Thanks!
0
 
hesCommented:
I did... My first click gave me a value of 10 (there were was 1234567890 in the rtb) I added 20 more characters and the value was 30 I clicked on the first 5 and the value was 5
0
 
ttobin333Author Commented:
Hes, maybe you have a newer/different richtextbox control? Mine is definitely retuning the prior mousedown value each time. Are you using VB6?
0
 
aikimarkCommented:
what about the mousemove event?
0
 
hesCommented:
Yes I am using VB6 sp6
0
 
ttobin333Author Commented:
Regarding the mousemove event, using the click event is much simpler.

Regarding the difference in SelStart behavior, I don't know what the answer is. The behavior Hes describes is indeed what one would expect, and is the way a standard textbox behaves, but mine is not working that way.
0
 
ttobin333Author Commented:
Is there an updated RichTextbox control for VB6?
0
 
hesCommented:
This is a new pc I just installed VB6 then applied sp6 nothing else updated in VB6
0
 
ttobin333Author Commented:
I also have VB6 SP6, on 2 machines, Win7 and XP.

To test this issue again, I did as follows:
1. Created a new project, new form, new RichTextbox
2. In the mousedown event, I entered the code: msgbox str(richtextbox1.SelStart).
3. I ran the project
4. I entered 12345 into the RichTextbox
5. I clicked between the characters 1 and 2
6. The mousedown value = 5, the prior value
7. I clicked between the characters 3 and 4
8. The mousedown value = 1, again the prior value

When the RichTextbox has pre-loaded text upon opening, mousedown returns 0 on the first click because the default SelStart is at zero when it first opens.

This appears to be an inherent problem with the RichTextbox control, and at this point it is not productive to further pursue the issue, because the click event is a satisfactory workaround.
0
 
ttobin333Author Commented:
Will use click event rather than mousedown, as a work-around.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.