2个回答
2013-05-14
展开全部
好像只能计算回车键的个数,来做
int selstart = this.richTextBox1.SelectionStart;
int i = 0;
int rowNum = 1;//行号;
foreach (char ch in richTextBox1.Text)
{
if (ch == '\n')
{
rowNum++;
}
if (i > selstart)
{
break;
}
}
int j = 0;
try
{
j = this.richTextBox1.Text.LastIndexOf("\n", selstart - 1 > 1 ? selstart - 1 : 1);
}
catch { }
int lineNum = selstart - j;
this.toolStripStatusLabel2.Text = "行: " + rowNum.ToString() + " 列:" + lineNum.ToString() + " ";
int selstart = this.richTextBox1.SelectionStart;
int i = 0;
int rowNum = 1;//行号;
foreach (char ch in richTextBox1.Text)
{
if (ch == '\n')
{
rowNum++;
}
if (i > selstart)
{
break;
}
}
int j = 0;
try
{
j = this.richTextBox1.Text.LastIndexOf("\n", selstart - 1 > 1 ? selstart - 1 : 1);
}
catch { }
int lineNum = selstart - j;
this.toolStripStatusLabel2.Text = "行: " + rowNum.ToString() + " 列:" + lineNum.ToString() + " ";
2013-05-14
展开全部
//显示光标所在的行数和列数
private void richTextBox1_MouseClick(object sender, MouseEventArgs e)
{
int x = e.Location.X - richTextBox1.Location.X;
int y = e.Location.Y - richTextBox1.Location.Y;
int fontheight = this.richTextBox1.Font.Height;
int fontwidth = Convert.ToInt32(richTextBox1.Font.Size);
int row = (y / fontheight) + 1;
int line = (x / fontwidth) + 1;
this.toolStripStatusLabel6.Text = "行 " + row.ToString() + " 列 " + line.ToString(); ;
}
这是我用WinForm做的时候用的方法;你可以看哈哦
private void richTextBox1_MouseClick(object sender, MouseEventArgs e)
{
int x = e.Location.X - richTextBox1.Location.X;
int y = e.Location.Y - richTextBox1.Location.Y;
int fontheight = this.richTextBox1.Font.Height;
int fontwidth = Convert.ToInt32(richTextBox1.Font.Size);
int row = (y / fontheight) + 1;
int line = (x / fontwidth) + 1;
this.toolStripStatusLabel6.Text = "行 " + row.ToString() + " 列 " + line.ToString(); ;
}
这是我用WinForm做的时候用的方法;你可以看哈哦
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询