>> Cursor Position in textbox

G

Guest

Hi, I have a textbox that users enter an email message. Next to this textbox
is a list of placeholders (for example <<Customer>> and <<Contact Full
Name>>). A user can enter some text and then insert a placeholder (later in
the code these placeholders are replaced by field values).

I use the syntax txtBody.selstart to locate the position of the cursor to
know where to locate the placeholder.

The problem is this. If the user is entering text and then double-clicks a
placeholder list item, txtBody.selstart = 0. However, if the user enters
text, then goes to another control before returning to the txtBody. That is,
the user wants to insert a placeholder list item into existing txtBody text.
In this instance txtBody=45 or whatever the actual cursor position is.

In short, whilst editing text, txtBody.selstart=0.

How can I get the position of the cursor whether the user is entering new
content, navigating within new content (I have tried using _OnChange event)
or has existing content?

Any ideas or suggestions appreciated :)

Many thanks, Jonathan
 
K

Ken Snell \(MVP\)

You cannot override where a "click" or "double-click" action from the mouse
puts the cursor. That is by design. The only way you can control the
location of the cursor is if the user tabs into the control, or if code puts
the focus on the control.
 
G

Guest

Ken Snell (MVP) said:
You cannot override where a "click" or "double-click" action from the mouse
puts the cursor. That is by design. The only way you can control the
location of the cursor is if the user tabs into the control, or if code puts
the focus on the control.
Ken thanks for responding to this post.

What I would like to know is the last position of the cursor in the txtbody
control when the user double-clicked an item in the placeholder pick listbox.
I want to know this position so that I can then use text functions to insert
the selected placeholder into the txtBody.text string.

At the moment I am always appending the placeholder to the end of the
txtBody.text string (this works) and I would like to extend the flexibility
of this routine. So that a user can enter content and go back using keys or
pointer, then insert a placeholder selected in the listbox at this location.

If there is no other alternative, then users will just have to get used to
the limitation of this feature...

Many thanks, Jonathan
 
J

John Nurick

Have you tried using code in the text box's Exit or Lost Focus event
procedure to store its SelStart and SelLength properties?
 
G

Guest

John Nurick said:
Have you tried using code in the text box's Exit or Lost Focus event
procedure to store its SelStart and SelLength properties?

Hi John, Yes... same result => when editing the selstart value is zero. When
positioning cursor in existing text (that is, have re-entered control),
selstart value is actual position in text.

It seems to me that the only way to achieve this will be to record key
stroke to calculate position; which seems rather extreme.

Many thanks, Jonathan
 
G

Guest

Hi John, the answer is to use the _beforeUpdate event. This suggests that the
update event re-sets the .SelStart position.

Many thanks, Jonathan
 

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