简体   繁体   中英

how to set the cursor position in a non textbox component

I am working with a component named SpinEdit that has a text property. how would I set the cursor position in this component ?

You can't unless it exposes a SelectionStart property, or similar.

The Text property is a string, which bears no relation to the cursor within the editor.

If it does expose a SelectionStart property, then you can usually get and set that to get and set the cursor index within the control programatically.

In response to your comment, you set the SelectionStart property of most controls that have it by giving it an int value. For example, to set the cursor to the start of the Control:

Control.SelectionStart = 0;

To set the cursor to the end of the control:

Control.SelectionStart = Control.Text.Length -1;

But, these will only work if the control you are using has the property and allows it to be set. You've not specified where the control comes from, so until you give us more information, there's nothing else we can do to help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM