NSTextField positioning the cursor

Hi everyone,

This is a quick one, so I was in the need of change the position of the cursor of one NSTextField, because it pre-fill the field with a partial value which came from another field (Let’s say I selected a country on one field and the state field had to came with the prefix of the country code). Easy task, right? it wasn’t so obvious for me.

One way of doing this is by using the SelectedRange property of CurrentEditor property that NSTextField have.

  • NSTextField don’t have an SelectedRange property directly, but NSText did have it.
  • CurrentEditor is and object of type NSText

With the code of above we send the cursor to the end of the string that the field have.

Quick and easy.

Share This:

.NET Entusiast

Leave a Reply

Your email address will not be published. Required fields are marked *

Facebook Auto Publish Powered By : XYZScripts.com