如何显示一个RichTextBox C#中的行数 [英] How to show number of a line in a RichTextBox C#

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

问题描述

我正在使用的代码高亮一个简单的文本和脚本编辑器。对于我使用一个RichTextBox。但我不知道如何使它显示在左侧的线'号,就像在VS或记事本+ +。有没有什么解决办法吗?

I am making a simple text and script editor with code highlighting. For that I use a RichTextBox. But I don't know how to make it show the lines' numbers on the left side, like in VS or Notepad++. Is there any solution?

推荐答案

我试图重新使用从其他地方引用的CodeProject上的文章的代码,但我看着每一个选项,显得有点太缺憾。

I tried re-using the code from the codeproject articles referenced elsewhere, but every option I looked at, seemed a bit too kludgy.

所以,我建立了一个显示行数另一个RichTextBoxEx。

So I built another RichTextBoxEx that displays line numbers.

行编号可开启或关闭。这是快。它滚动干净。可以选择数字,背景颜色的梯度,边界厚度,字体的颜色,是否使用前导零。您可以选择行数为显示或根据在RTB硬换行。

The line numbering can be turned on or off. It's fast. It scrolls cleanly. You can select the color of the numbers, the background colors for a gradient, the border thickness, the font, whether to use leading zeros. You can choose to number lines "as displayed" or according to the hard newlines in the RTB.

例如:

替换文本

它的局限性:它只能在左边显示的数字。你可以改变没有太多精力,如果你在意。

It has limitations: it displays numbers only on the left. You could change that without too much effort if you cared.

中的代码被设计为C#项目。虽然这是一个更大的解决方案(一个XPath可视化工具)的一部分,自定义的RichTextBox打包为一个可分离的组件,并准备在新项目中使用。在Visual Studio中,只需添加一个参考的DLL,你可以拖动和拖放到您的设计上。你可以丢弃的大型解决方案的其他代码。

The code is designed as C# project. Though it's part of a larger "solution" (an XPath Visualization tool), the custom RichTextBox is packaged as a separable assembly, and is ready to use in your new projects. In Visual Studio, just add a reference to the DLL, and you can drag-and-drop it onto your design surface. You can just discard the other code from the larger solution.

看到代码

这篇关于如何显示一个RichTextBox C#中的行数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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