get linenumber

int totalline = textBox1.GetLineFromCharIndex(textBox1.Text.Length) + 1;//得到总行数。该行数会随着文本框的大小改变而改变;

若只认回车符为一行(不考虑排版变化)请用

总行数=textBox1.Lines.Length;(记事本2是这种方式)
            int index = textBox1.GetFirstCharIndexOfCurrentLine();//得到当前行第一个字符的索引
            int line = textBox1.GetLineFromCharIndex(index) + 1;//得到当前行的行号,从0开始,习惯是从1开始,所以+1.
            int col = textBox1.SelectionStart - index + 1;//.SelectionStart得到光标所在位置的索引 减去 当前行第一个字符的索引 = 光标所在的列数(从0开始)

posted @ 2010-01-01 23:10  greencolor  阅读(121)  评论(0编辑  收藏  举报