在格式文本框C#中显示行号 [英] displaying line number in rich text box c#

查看:523
本文介绍了在格式文本框C#中显示行号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经到了我要整合添加行号的功能的多行RichTextBox控件。我也考虑过很多办法


  1. 添加标签和更新行号作为行数的变化

  2. 添加图片框以及在其上描绘的字符串。

  3. 用,并显示行号一起添加另一个文本框就可以了

  4. 在沿着与显示行号添加列表框。

我有两个疑问。


  1. 我使用的RichTextBox的是一个定制的控制和derieves从RichTextBox的类。如何添加多个控件到它。

  2. 什么是显示行号在C#中的多行文字
  3. 最好的办法

解决方案

我自己的例子。一切都很好,但是换行必须禁用:(

  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

  1. Add a label and updating the line numbers as the line count changes
  2. Add a picturebox along with to draw string on it.
  3. Add another textbox along with and show line numbers on it
  4. Add listbox along and display line numbers in it.

I got two doubts.

  1. The richtextbox which i'm using is a custom made control and derieves from RichTextBox class. How can i add multiple controls to it.
  2. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆