【发布时间】:2013-02-28 03:25:05
【问题描述】:
我得到了一个行编号代码,它非常适合以常规方式对行进行编号,但我正在寻找一些不同的东西。我希望我的代码仅在我按 Enter 键时计算换行符(程序收到返回键码),而不是文本框自动使用自动换行剪切行。这是我现在使用的代码:
//Instructions
int maxLC = 1; //maxLineCount - should be public
private void InstructionsSyncTextBox_KeyUp(object sender, KeyEventArgs e)
{
int linecount = InstructionsSyncTextBox.GetLineFromCharIndex(InstructionsSyncTextBox.TextLength) + 1;
if (linecount != maxLC)
{
InstructionsLineNumberSyncTextBox.Clear();
for (int i = 1; i < linecount + 1; i++)
{
InstructionsLineNumberSyncTextBox.AppendText(Convert.ToString(i) + "\n");
}
maxLC = linecount;
}
}
我认为最简单的方法是每次有人按 Enter 键时保存行数到列表中,并且每次有人按 Enter 键时都会更新行号 texbox,其中每个行号位于列表中的位置。但我不知道如何检测退货何时被删除。有人知道怎么解决吗?
【问题讨论】:
-
你不能只使用正则表达式并搜索 \r 的所有实例吗?
标签: c# return word-wrap line-numbers