在格式文本框C#中显示行号 [英] displaying line number in rich text box c#
本文介绍了在格式文本框C#中显示行号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经到了我要整合添加行号的功能的多行RichTextBox控件。我也考虑过很多办法
- 添加标签和更新行号作为行数的变化
- 添加图片框以及在其上描绘的字符串。
- 用,并显示行号一起添加另一个文本框就可以了
- 在沿着与显示行号添加列表框。
我有两个疑问。
- 我使用的RichTextBox的是一个定制的控制和derieves从RichTextBox的类。如何添加多个控件到它。
- 什么是显示行号在C#中的多行文字 最好的办法
解决方案
我自己的例子。一切都很好,但是换行必须禁用:(
INT maxLC = 1; // maxLineCount - 应该是公开的
私人无效rTB_KeyUp(对象发件人,发送KeyEventArgs E)
{
INT linecount = rTB.GetLineFromCharIndex(rTB.TextLength)+ 1;
如果(linecount!= maxLC)
{
tB_line.Clear();
的for(int i = 1; I< linecount + 1;我++)
{
tB_line.AppendText(Convert.ToString(ⅰ)+\\ n);
}
maxLC = linecount;
}
}
其中RTB是我的RichTextBox和Tb毗邻RTB的textBox
J.T。 JR
I have a Multiline richtextbox control into which i want to integrate the feature of adding a line number. i have considered many approaches
- Add a label and updating the line numbers as the line count changes
- Add a picturebox along with to draw string on it.
- Add another textbox along with and show line numbers on it
- Add listbox along and display line numbers in it.
I got two doubts.
- The richtextbox which i'm using is a custom made control and derieves from RichTextBox class. How can i add multiple controls to it.
- What is the best approach to show line numbers for the multiline text in c#
解决方案
My own example. All is fine, but wordwrap must be disabled :(
int maxLC = 1; //maxLineCount - should be public
private void rTB_KeyUp(object sender, KeyEventArgs e)
{
int linecount = rTB.GetLineFromCharIndex( rTB.TextLength ) + 1;
if (linecount != maxLC)
{
tB_line.Clear();
for (int i = 1; i < linecount+1; i++)
{
tB_line.AppendText(Convert.ToString(i) + "\n");
}
maxLC = linecount;
}
}
where rTB is my richtextbox and tB is textBox next to rTB
J.T. jr
这篇关于在格式文本框C#中显示行号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文