在多行文本框中开始 [英] selectionStart in multiline textbox

查看:146
本文介绍了在多行文本框中开始的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

解决方案

如果我正确理解该问题,则以下内容应该起作用

  int  lineNum =  3 ;
textBox1.SelectionStart = textBox1.GetFirstCharIndexFromLine(lineNum); 




GetFirstCharIndexFromLine获取指定行上第一个字符的字符索引,将选择开始设置为此将意味着您的选择从该行的开始开始.



只是增加一点,在解决方案2的注释中,您说您想将选择的起始位置定位在行的任意点而不仅仅是起始位置,为此只需添加要从中缩进的字符数该行的开头:

  int  lineNum =  3 ;
 int  characterNum =  5 ;
textBox1.SelectionStart = textBox1.GetFirstCharIndexFromLine(lineNum)+ characterNum; 


除了GParkings解决方案外,还请参阅给定的文章来演示GetFirstCharIndexOfCurrentLine()函数.
获取当前的插入符多行Windows窗体文本框中的行和列 [ 解决方案

If i undertsand the question correctly the following should work

int lineNum = 3;
textBox1.SelectionStart = textBox1.GetFirstCharIndexFromLine(lineNum);




GetFirstCharIndexFromLine gets the character index of the first character on the specified line, setting the selection start to this will mean your selection starts from the beginning of that line.

EDIT:

just to add a bit more, in your comment in solution 2 you say you want to position the selection start at an arbitrary point along the line not just at the beginning, to do that simply add the number of characters you want to indent from the beginning of the line:

int lineNum = 3;
int characterNum = 5;
textBox1.SelectionStart = textBox1.GetFirstCharIndexFromLine(lineNum) + characterNum;


In addition to GParkings solution have a look at given article which demonstrating the GetFirstCharIndexOfCurrentLine() function.
Get current Caret Line and Column in a multiline Windows Forms TextBox[^]


Yes - but it works in terms of character position, so you will have to work out the line based on that, including the length of all the line above where you want the caret to go.


这篇关于在多行文本框中开始的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆