Strider007
Strider007

Reputation: 4945

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 ?

Upvotes: 0

Views: 535

Answers (1)

djdd87
djdd87

Reputation: 68476

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.

Upvotes: 1

Related Questions