[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 265
  • Last Modified:

How to control cursor and backspac's position in edit control?

I have an edit control, how I set the cursor to the position that I want within this control, for example, after I type two characters, I don't want the cursor stay at third position instead I want the cursor jump to the fouth position. The same thing for "back space" key, if there is a text in control, and I used this key to delete from the end of text, but I don't want to delete a special character in this text, how to let "back space" jump over from this character to next character.

Thanks.
Hanqian
 
0
Hanqian
Asked:
Hanqian
  • 3
  • 2
  • 2
2 Solutions
 
AlexFMCommented:
CEdit::SetSel function with equal values of nStartChar and nEndChar parameters sets cursor to specified position. For example:

pEdit->SetSel(1, 1);

sets cursor after first character in the control.
0
 
HanqianAuthor Commented:
I have tried it, it doesn't work. After I type two chars. I use pEdit->SetSel(4, 4), it doesn't go to the position 4.

Hanqian
0
 
AndyAinscowCommented:
I assume your control is empty when you start typing.
You would need to add the third (space) character yourself then position at the end (4th) position.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
HanqianAuthor Commented:
I did add "/" at third position.

Hanqian
0
 
AlexFMCommented:
If edit control has 3 characters, you can write:

pEdit->SetSel(3, 3);

4 is still out of range.
0
 
HanqianAuthor Commented:
That means that we can't use SetSel() to set the cursor at the blank position of the edit control.

Hanqian
0
 
AndyAinscowCommented:
Set it at the end of the text as I said earlier.  As Alex says if you only have 3 chars then the fourth doesn't exist.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now