save position of cursor in a textbox

T

TNL

Hi,
I have a textbox, I want to save the cursor postion in this textbox in a
variable, when user leaves it ( event lostFocus).
When user click a button, a correspond. text will be insert in the actual
position.

But on event Lostfocus I receive only value 0:

private iPos as integer
Private Sub txtRegel_LostFocus()
iPos = txtRegel.SelStart
End Sub

Can anybody help me.
Thanks
 
M

Marshall Barton

TNL said:
I have a textbox, I want to save the cursor postion in this textbox in a
variable, when user leaves it ( event lostFocus).
When user click a button, a correspond. text will be insert in the actual
position.

But on event Lostfocus I receive only value 0:

private iPos as integer
Private Sub txtRegel_LostFocus()
iPos = txtRegel.SelStart
End Sub


The issue here is that the text box's AfterUpdate event
clears the Sel... properties. This means that you need to
use the BeforeUpdate event to save SelStart when the text
box was edited. Use the LostFocus event to save SelStart
when the text box was just clicked on whtout changing it.

You'll need to clear a module level flag variable in the
GotFocus event and set it in the BeforeUpdate event so the
LostFocus event can tell if it was edited or not.
 
M

Marshall Barton

TNL said:
Thanks very much.
It works correctly.

You're welcome.

Is this documented anywhere?

No, not that I've ever heard of.
I just kind of figured it out using trial,
error, intuition and 40 years of
programming experience ;-)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top