简体   繁体   English

如何在非文本框组件中设置光标位置

[英]how to set the cursor position in a non textbox component

I am working with a component named SpinEdit that has a text property. 我正在使用一个具有文本属性的名为SpinEdit的组件。 how would I set the cursor position in this component ? 如何在此组件中设置光标位置?

You can't unless it exposes a SelectionStart property, or similar. 除非它公开了SelectionStart属性或类似属性,否则您将无法进行。

The Text property is a string, which bears no relation to the cursor within the editor. Text属性是一个字符串,与编辑器中的光标无关。

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. 如果它确实公开了SelectionStart属性,则通常可以以编程方式获取并设置该值以获取并设置控件中的光标索引。

In response to your comment, you set the SelectionStart property of most controls that have it by giving it an int value. 作为对您的评论的回应,可以通过为它提供一个int值来设置大多数具有它的控件的SelectionStart属性。 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. 您尚未指定控件的来源,因此在您向我们提供更多信息之前,我们无能为力。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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