还有,我在网上搜到了这样一段,感觉跟我遇到的情况相似:
在开发一个小工具的过程中,TextBox的文本很长,好不容易将光标定位到指定位置了,一点窗体中的任何按钮,光标就回到TextBox的顶端了,很不爽。
经过一翻研究后,终于可以使光标定位到原位置了。
示例代码如下:
string alltext = this.txtDocumentConent.Text.Trim();
string selecttext = this.txtDocumentConent.SelectedText;
int i = alltext.IndexOf(selecttext);
if (!string.IsNullOrEmpty(selecttext))
{
//自定义操作
}
if (i >= 0)
{
this.txtDocumentConent.Focus();
this.txtDocumentConent.SelectionStart = i;
this.txtDocumentConent.SelectionLength = selecttext.Length;
this.txtDocumentConent.ScrollToCaret();
}
请问:这段代码如何转换到狐表中来,能放在窗口事件的什么位置?