How to track current index in the textbox string

  • Thread starter Thread starter Fiaz Ali Saleemi
  • Start date Start date
F

Fiaz Ali Saleemi

Hi All

I have developed a custom user control for onscreen Keyboard functionality.
When user clicks any button then it should act accordingly and add the
appropriate character into the string or do the appropriate action(Delete,
Backspace etc).
Now if user sets cursor in the middle of the string in textbox and then
clicks
keyboards button for example 'a' then how to find the index where cursor
exist in the textbox and add 'a' to that perticullar location. At the moment
I am adding every character on the last index of the string but this is not
appropriate.
Any hint or any solution which can help me get going will be highly
appreciated.


Thanks In Advance


Regards
Fiaz Ali Saleemi
 
If you know that SelectionLength is 0 you can simply use SelectionStart

However, if SelectionLength is not 0, the caret can be at either end of the
selection, meaning SelectionStart is of no use to you. In that case you'll
need to use P/Invoke and call GetCaretPos and then issue a EM_CHARFROMPOS
message to the textbox


Another approach is to put your character on the clipboard and the call the
Paste method. That would put it at the correct location automatically. You
might want to save the old clipboard content first so you can restore it
afterwards.

/claes
 
Hi Claes

It did solved my problem, I am very thankful to you.

Best Wishes
Fiaz Ali Saleemi
 
Back
Top