- 定义一个TextBox文本框textbox
- 定义一个int rowIndex来确定选择哪一行
try{
//开始位置
int start = textbox.GetCharacterIndexFromLineIndex(rowIndex);
//长度
int length = textbox.GetLineText(rowIndex).Length;
//int length=textbox.GetLineLength(rowIndex);//这条语句可能会报错
textbox.Focus();
//选择指定行内容
textbox.Select(start, length);
textbox.ScrollToLine(rowIndex);
}
catch
{
}
3.可以对rowIndex进行验证(是否超出范围)
if (rowIndex < 0)
{
rowIndex = 0;
}
if (rowIndex > tooltipText.LineCount - 1)
{
rowIndex = textbox.LineCount - 1;
}