C#实现带行数和标尺的RichTextBox

目录
  • 实践过程
    • 效果
    • 代码

实践过程

效果

代码

 public partial class GuageRichTextBox : UserControl
    {
        public GuageRichTextBox()
        {
            InitializeComponent();
            richTextBox1.WordWrap = false;
            richTextBox1.Top = Distance_X;
            richTextBox1.Left = Distance_Y;
            richTextBox1.Width = this.Width - Distance_X - 2;
            richTextBox1.Height = this.Height - Distance_Y - 2;
        }

        #region 变量及常量

        const int Distance_X = 30; //设置RichTextBox控件的X位置
        const int Distance_Y = 30; //设置RichTextBox控件的Y位置
        const int SpaceBetween = 3; //设置标尺的间距
        public static float thisleft = 0; //设置控件的左边距
        public static float StartBitH = 0; //记录横向滚动条的位置
        public static float StartBitV = 0; //记录纵向滚动条的位置
        const int Scale1 = 3; //设置刻度最短的线长
        const int Scale5 = 6; //设置刻度为5时的线长
        const int Scale10 = 9; //设置刻度为10是垢线长
        public static float Degree = 0; //度数
        public static float CodeSize = 1; //代码编号的宽度

        #endregion

        #region 属性

        [Browsable(true), Category("设置标尺控件"), Description("设置RichTextBox控件的相关属性")] //在“属性”窗口中显示DataStyle属性
        public RichTextBox NRichTextBox
        {
            get { return richTextBox1; }
        }

        public enum Ruler
        {
            Graduation = 0, //刻度
            Rule = 1, //尺子
        }

        private bool TCodeShow = false;

        [Browsable(true), Category("设置标尺控件"), Description("是否在RichTextBox控件的前面添加代码的行号")] //在“属性”窗口中显示DataStyle属性
        public bool CodeShow
        {
            get { return TCodeShow; }
            set
            {
                TCodeShow = value;
                this.Invalidate();
            }
        }

        private Ruler TRulerStyle = Ruler.Graduation;

        [Browsable(true), Category("设置标尺控件"), Description("设置标尺样式:\nGraduation为刻度\nRule为尺子")] //在“属性”窗口中显示DataStyle属性
        public Ruler RulerStyle
        {
            get { return TRulerStyle; }
            set
            {
                TRulerStyle = value;
                this.Invalidate();
            }
        }

        public enum Unit
        {
            Cm = 0, //厘米
            Pels = 1, //像素
        }

        private Unit TUnitStyle = Unit.Cm;

        [Browsable(true), Category("设置标尺控件"), Description("设置标尺的单位:\nCm为厘米\nPels为像素")] //在“属性”窗口中显示DataStyle属性
        public Unit UnitStyle
        {
            get { return TUnitStyle; }
            set
            {
                TUnitStyle = value;
                this.Invalidate();
            }
        }

        #endregion

        #region 事件

        private void GuageRichTextBox_Paint(object sender, PaintEventArgs e)
        {
            e.Graphics.DrawRectangle(new Pen(Color.DarkGray), 0, 0, this.Width - 1, this.Height - 1); //绘制外边框
            if (CodeShow) //如查在文本框左边添加行号
            {
                //获取行号的宽度
                float tem_code =
                    (float) StringSize(
                        (Convert.ToInt32(CodeSize + (float) (richTextBox1.Height /
                                                             (StringSize(CodeSize.ToString(), richTextBox1.Font,
                                                                 false))))).ToString(), this.Font, true);
                richTextBox1.Top = Distance_X; //设置控件的顶端距离
                richTextBox1.Left = Distance_Y + (int) Math.Ceiling(tem_code); //设置控件的左端距离
                richTextBox1.Width = this.Width - Distance_X - 2 - (int) Math.Ceiling(tem_code); //设置控件的宽度
                richTextBox1.Height = this.Height - Distance_Y - 2; //设置控件高度
                thisleft = Distance_Y + tem_code; //设置标尺的左端位置
            }
            else
            {
                richTextBox1.Top = Distance_X; //设置控件的顶端距离
                richTextBox1.Left = Distance_Y; //设置控件的左端距离
                richTextBox1.Width = this.Width - Distance_X - 2; //设置控件的宽度
                richTextBox1.Height = this.Height - Distance_Y - 2; //设置控件高度
                thisleft = Distance_Y; //设置标尺的左端位置
            }

            //绘制文本框的边框
            e.Graphics.DrawRectangle(new Pen(Color.LightSteelBlue), richTextBox1.Location.X - 1, thisleft - 1,
                richTextBox1.Width + 1, richTextBox1.Height + 1);
            e.Graphics.FillRectangle(new SolidBrush(Color.Silver), 1, 1, this.Width - 2, Distance_Y - 2); //文本框的上边框
            e.Graphics.FillRectangle(new SolidBrush(Color.Silver), 1, 1, Distance_X - 2, this.Height - 2); //文本框的左边框
            e.Graphics.FillRectangle(new SolidBrush(Color.Gray), 3, 3, Distance_X - 7, Distance_Y - 8); //绘制左上角的方块边框
            e.Graphics.DrawRectangle(new Pen(SystemColors.Control), 3, 3, Distance_X - 8, Distance_Y - 8); //绘制左上角的方块
            if (RulerStyle == Ruler.Rule) //标尺
            {
                //绘制上边的标尺背景
                e.Graphics.FillRectangle(new SolidBrush(Color.Gray), thisleft - 3, 3, this.Width - (thisleft - 2),
                    Distance_Y - 9); //绘制左上角的方块边框
                e.Graphics.DrawLine(new Pen(SystemColors.Control), thisleft - 3, 3, this.Width - 2, 3); //绘制方块的上边线
                e.Graphics.DrawLine(new Pen(SystemColors.Control), thisleft - 3, Distance_Y - 5, this.Width - 2,
                    Distance_Y - 5); //绘制方块的下边线
                e.Graphics.FillRectangle(new SolidBrush(Color.WhiteSmoke), thisleft - 2, 9,
                    this.Width - (thisleft - 2) - 1, Distance_Y - 19); //绘制方块的中间块
                //绘制左边的标尺背景
                e.Graphics.FillRectangle(new SolidBrush(Color.Gray), 3, Distance_Y - 3, Distance_X - 7,
                    this.Height - (Distance_Y - 3) - 2); //绘制左边的方块
                e.Graphics.DrawLine(new Pen(SystemColors.Control), 3, Distance_Y - 3, 3, this.Height - 2); //绘制方块的左边线
                e.Graphics.DrawLine(new Pen(SystemColors.Control), Distance_X - 5, Distance_Y - 3, Distance_X - 5,
                    this.Height - 2); //绘制方块的右边线
                e.Graphics.FillRectangle(new SolidBrush(Color.WhiteSmoke), 9, Distance_Y - 3, Distance_X - 19,
                    this.Height - (Distance_Y - 3) - 2); //绘制方块的中间块
            }

            int tem_temHeight = 0;
            string tem_value = "";
            int tem_n = 0;
            int divide = 5;
            Pen tem_p = new Pen(new SolidBrush(Color.Black));
            //横向刻度的设置
            if (UnitStyle == Unit.Cm) //如果刻度的单位是厘米
                Degree = e.Graphics.DpiX / 25.4F; //将像素转换成毫米
            if (UnitStyle == Unit.Pels) //如果刻度的单位是像素
                Degree = 10; //设置10像素为一个刻度
            int tem_width = this.Width - 3;
            tem_n = (int) StartBitH; //记录横向滚动条的位置
            if (tem_n != StartBitH) //如果横向滚动条的位置值为小数
                StartBitH = (int) StartBitH; //对横向滚动条的位置进行取整
            for (float i = 0; i < tem_width;) //在文本框的项端绘制标尺
            {
                tem_temHeight = Scale1; //设置刻度线的最小长度
                float j = (i + (int) StartBitH) / Degree; //获取刻度值
                tem_value = "";
                j = (int) j; //对刻度值进行取整
                if (j % (divide * 2) == 0) //如果刻度值是10进位
                {
                    tem_temHeight = Scale10; //设置最长的刻度线
                    if (UnitStyle == Unit.Cm) //如果刻度的单位为厘米
                        tem_value = Convert.ToString(j / 10); //记录刻度值
                    if (UnitStyle == Unit.Pels) //如果刻度的单位为像素
                        tem_value = Convert.ToString((int) j * 10); //记录刻度值
                }
                else if (j % divide == 0) //如果刻度值的进位为5
                {
                    tem_temHeight = Scale5; //设置刻度线为中等
                }

                tem_p.Width = 1;
                if (RulerStyle == Ruler.Graduation) //如果是以刻度值进行测量
                {
                    //绘制刻度线
                    e.Graphics.DrawLine(tem_p, i + 1 + thisleft, SpaceBetween, i + 1 + thisleft,
                        SpaceBetween + tem_temHeight);
                    if (tem_value.Length > 0) //如果有刻度值
                        //绘制刻度值
                        ProtractString(e.Graphics, tem_value.Trim(), i + 1 + thisleft, SpaceBetween, i + 1 + thisleft,
                            SpaceBetween + tem_temHeight, 0);
                }

                if (RulerStyle == Ruler.Rule) //如果是以标尺进行测量
                {
                    if (tem_value.Length > 0) //如果有刻度值
                    {
                        e.Graphics.DrawLine(tem_p, i + 1 + thisleft, 4, i + 1 + thisleft, 7); //绘制顶端的刻度线
                        e.Graphics.DrawLine(tem_p, i + 1 + thisleft, Distance_Y - 9, i + 1 + thisleft,
                            Distance_Y - 7); //绘制底端的刻度线
                        float tem_space = 3 + (Distance_X - 19F - 9F - StringSize(tem_value.Trim(), this.Font, false)) /
                            2F; //设置文本的横向位置
                        //绘制文本
                        ProtractString(e.Graphics, tem_value.Trim(), i + 1 + thisleft, (float) Math.Ceiling(tem_space),
                            i + 1 + thisleft, (float) Math.Ceiling(tem_space) + tem_temHeight, 0);
                    }
                }

                i += Degree; //累加刻度的宽度
            }

            //纵向刻度的设置
            if (UnitStyle == Unit.Cm) //如果刻度的单位是厘米
                Degree = e.Graphics.DpiX / 25.4F; //将像素转换成毫米
            if (UnitStyle == Unit.Pels) //如果刻度的单位是像素
                Degree = 10; //刻度值设为10像素
            int tem_height = this.Height - 3;
            tem_n = (int) StartBitV; //记录纵向滚动条的位置
            if (tem_n != StartBitV) //如果纵向滚动条的位置为小数
                StartBitV = (int) StartBitV; //对其进行取整
            for (float i = 0; i < tem_height;) //在文本框的左端绘制标尺
            {
                tem_temHeight = Scale1; //设置刻度线的最小值
                float j = (i + (int) StartBitV) / Degree; //获取当前的刻度值
                tem_value = "";
                j = (int) j; //对刻度值进行取整
                if (j % 10 == 0) //如果刻度值是10进位
                {
                    tem_temHeight = Scale10; //设置刻度线的长度为最长
                    if (UnitStyle == Unit.Cm) //如果刻度的单位是厘米
                        tem_value = Convert.ToString(j / 10); //获取厘米的刻度值
                    if (UnitStyle == Unit.Pels) //如果刻度的单位是像素
                        tem_value = Convert.ToString((int) j * 10); //获取像素的刻度值
                }
                else if (j % 5 == 0) //如果刻度值是5进位
                {
                    tem_temHeight = Scale5; //设置刻度线的长度为中等
                }

                tem_p.Width = 1;
                if (RulerStyle == Ruler.Graduation) //如果是以刻度值进行测量
                {
                    //绘制刻度线
                    e.Graphics.DrawLine(tem_p, SpaceBetween, i + 1 + Distance_Y, SpaceBetween + tem_temHeight,
                        i + 1 + Distance_Y);
                    if (tem_value.Length > 0) //如果有刻度值
                        //绘制刻度值
                        ProtractString(e.Graphics, tem_value.Trim(), SpaceBetween, i + 1 + Distance_Y,
                            SpaceBetween + tem_temHeight, i + 1 + Distance_Y, 1);
                }

                if (RulerStyle == Ruler.Rule) //如果是以标尺进行测量
                {
                    if (tem_value.Length > 0) //如果有刻度值
                    {
                        e.Graphics.DrawLine(tem_p, 4, i + 1 + Distance_Y, 7, i + 1 + Distance_Y); //绘制左端刻度线
                        e.Graphics.DrawLine(tem_p, Distance_Y - 9, i + 1 + Distance_Y, Distance_Y - 7,
                            i + 1 + Distance_Y); //绘制右端刻度线
                        float tem_space = 3 + (Distance_X - 19F - 9F - StringSize(tem_value.Trim(), this.Font, false)) /
                            2F; //设置文本的纵向位置
                        //绘制文本
                        ProtractString(e.Graphics, tem_value.Trim(), (float) Math.Floor(tem_space), i + 1 + Distance_Y,
                            (float) Math.Floor(tem_space) + tem_temHeight, i + 1 + Distance_Y, 1);
                    }
                }

                i += Degree; //累加刻度值
            }

            if (CodeShow) //如果显示行号
            {
                //设置文本的高度
                float tem_FontHeight =
                    (float) (richTextBox1.Height / (StringSize(CodeSize.ToString(), richTextBox1.Font, false)));
                float tem_tep = richTextBox1.Top; //获取文本框的顶端位置
                int tem_mark = 0;
                for (int i = 0; i < (int) tem_FontHeight; i++) //绘制行号
                {
                    tem_mark = i + (int) CodeSize; //设置代码编号的宽度
                    //绘制行号
                    e.Graphics.DrawString(tem_mark.ToString(), this.Font, new SolidBrush(Color.Red),
                        new PointF(richTextBox1.Left - StringSize(tem_mark.ToString(), this.Font, true) - 2, tem_tep));
                    tem_tep = tem_tep + StringSize("懂", richTextBox1.Font, false); //设置下一个行号的X坐标值
                }
            }
        }

        private void GuageRichTextBox_Resize(object sender, EventArgs e)
        {
            richTextBox1.Top = Distance_X; //设置控件的顶端位置
            richTextBox1.Left = Distance_Y; //设置控件的左端位置
            richTextBox1.Width = this.Width - Distance_X - 2; //设置控件的宽度
            richTextBox1.Height = this.Height - Distance_Y - 2; //设置控件的高度
            this.Invalidate();
        }

        private void richTextBox1_HScroll(object sender, EventArgs e)
        {
            StartBitH = (int) (Math.Abs((float) richTextBox1.GetPositionFromCharIndex(0).X - 1)); //检索控件横向内指定字符索引处的位置
            this.Invalidate();
        }

        private void richTextBox1_VScroll(object sender, EventArgs e)
        {
            StartBitV = (int) (Math.Abs((float) richTextBox1.GetPositionFromCharIndex(0).Y - 1)); //检索控件纵向内指定字符索引处的位置
            if (CodeShow) //如果显示行号
                CodeSize = (int) Math.Abs((richTextBox1.GetPositionFromCharIndex(0).Y /
                                           StringSize("懂", richTextBox1.Font, false))); //设置行号的高度
            this.Invalidate();
        }

        #endregion

        #region 方法

        /// <summary>
        /// 在指定的位置绘制文本信息
        /// </summary>
        /// <param e="Graphics">封装一个绘图的类对象</param>
        /// <param str="string">文本信息</param>
        /// <param x1="float">左上角x坐标</param>
        /// <param y1="float">左上角y坐标</param>
        /// <param x2="float">右下角x坐标</param>
        /// <param y2="float">右下角y坐标</param>
        /// <param n="float">标识,判断是在横向标尺上绘制文字还是在纵向标尺上绘制文字</param>
        public void ProtractString(Graphics e, string str, float x1, float y1, float x2, float y2, float n)
        {
            float TitWidth = StringSize(str, this.Font, true); //获取字符串的宽度
            if (n == 0) //在横向标尺上绘制文字
                e.DrawString(str, this.Font, new SolidBrush(Color.Black), new PointF(x2 - TitWidth / 2, y2 + 1));
            else //在纵向标尺上绘制文字
            {
                StringFormat drawFormat = new StringFormat(); //实例化StringFormat类
                drawFormat.FormatFlags = StringFormatFlags.DirectionVertical; //设置文本为垂直对齐
                //绘制指定的文本
                e.DrawString(str, this.Font, new SolidBrush(Color.Black), new PointF(x2 + 1, y2 - TitWidth / 2),
                    drawFormat);
            }
        }

        /// <summary>
        /// 获取文本的高度或宽度
        /// </summary>
        /// <param str="string">文本信息</param>
        /// <param font="Font">字体样式</param>
        /// <param n="bool">标识,判断返回的是高度还是宽度</param>
        public float StringSize(string str, Font font, bool n) //n==true为width
        {
            Graphics TitG = this.CreateGraphics(); //创建Graphics类对象
            SizeF TitSize = TitG.MeasureString(str, font); //将绘制的字符串进行格式化
            float TitWidth = TitSize.Width; //获取字符串的宽度
            float TitHeight = TitSize.Height; //获取字符串的高度
            if (n)
                return TitWidth; //返回文本信息的宽度
            else
                return TitHeight; //返回文本信息的高度
        }

        #endregion
    }

以上就是C#实现带行数和标尺的RichTextBox的详细内容,更多关于C# RichTextBox的资料请关注我们其它相关文章!

(0)

相关推荐

  • C#实现两个richtextbox控件滚动条同步滚动的简单方法

    前言 有时候我们需要实现对照文章等,往往将文本放到两个richtextbox控件中,但是,如果我们需要同步滚动查看,来达到更好的观看效果. 当然,传统的方法重载控件或者自定义控件都可以达到目的,但是对于新手或者想仅仅只用一次这个控件的人来说,是非常麻烦的.所以,接下来我来提供一种简单快捷的方法来实现:richtextbox滚动条同步的功能. 方法如下: 首先,我们在winform窗体创建两个richtextbox控件 下面介绍两个方法,我经常用到 第一个方法,获得当前鼠标所在richtextbo

  • C#中richtextbox使用方法详解

    C#中RichTextBox使用方法和TextBox基本一样,只不过RichText除了TXT外,还支持RTF格式的文档.本文详细介绍RichTextBox的使用方法供大家参考,具体如下: 一.RichTextBox的使用方法 RichTextBox.Find方法 RichTextBox控件不仅允许输入和编辑文本,同时还提供了标准 TextBox 控件未具有的.更高级的指定格式的许多功能. 语法:RichTextBox 说明: RichTextBox 提供了一些属性,对于本控件文本的任何部分,用

  • C# Winform使用扩展方法实现自定义富文本框(RichTextBox)字体颜色

    在利用C#开发Winform应用程序的时候,我们有可能使用RichTextBox来实现实时显示应用程序日志的功能,日志又分为:一般消息,警告提示和错误等类别.为了更好地区分不同类型的日志,我们需要使用不同的颜色来输出对应的日志,比如:一般消息为绿色,警告提示的用橙色,错误的用红色字体. 在原生Winform的RichTextBox中,是没有这种设置选项的.如需实现以上描述的功能,我们可以使用.NET的静态扩展方法来处理.实现扩展方法的类和方法本身都必须是静态的,如果你对扩展方法还不是太了解,建议

  • C#使用RichTextBox实现替换文字及改变字体颜色功能示例

    本文实例讲述了C#使用RichTextBox实现替换文字及改变字体颜色功能.分享给大家供大家参考,具体如下: 替换文字 private void GenerateEntity() { try { string result = ChangeWords("specific content..."); txtContent.Text = result; ChangeColor(); } catch (Exception ex) { MessageBox.Show("类生成失败!错

  • C# RichTextBox制作文本编辑器

    本文利用一个简单的小例子[文本编辑器],讲解RichTextBox的用法. Windows窗体中的RichTextBox控件用于显示,输入和操作格式化的文本,RichTextBox除了拥有TextBox控件的所有功能外,还可以显示字体,颜色,链接,从文件中读取和加载图像,以及查找指定的字符.RichTextBox控件通常用于提供类似字体处理程序(如Microsoft Word)的文本操作和显示功能.RichTextBox控件可以显示滚动条,且默认根据需要进行显示. 涉及知识点: Selectio

  • C#在RichTextBox中显示不同颜色文字的方法

    本文实例讲述了C#在RichTextBox中显示不同颜色文字的方法.分享给大家供大家参考.具体实现方法如下: #region 日志记录.支持其他线程访问 public delegate void LogAppendDelegate(Color color, string text); /// <summary> /// 追加显示文本 /// </summary> /// <param name="color">文本颜色</param> /

  • C#实现带行数和标尺的RichTextBox

    目录 实践过程 效果 代码 实践过程 效果 代码 public partial class GuageRichTextBox : UserControl { public GuageRichTextBox() { InitializeComponent(); richTextBox1.WordWrap = false; richTextBox1.Top = Distance_X; richTextBox1.Left = Distance_Y; richTextBox1.Width = this.

  • mysql获取group by的总记录行数另类方法

    mysql获取group by内部可以获取到某字段的记录分组统计总数,而无法统计出分组的记录数. mysql的SQL_CALC_FOUND_ROWS 使用 获取查询的行数 在很多分页的程序中都这样写: 代码如下 SELECT COUNT(*) from `table` WHERE ......; 查出符合条件的记录总数 代码如下 SELECT * FROM `table` WHERE ...... limit M,N; 查询当页要显示的数据 这样的语句可以改成: 代码如下 SELECT SQL_

  • mysql获取group by总记录行数的方法

    本文实例讲述了mysql获取group by总记录行数的方法,分享给大家供大家参考.具体方法分析如下: 一般来说,mysql获取group by内部可以获取到某字段的记录分组统计总数,而无法统计出分组的记录数. mysql中可以使用SQL_CALC_FOUND_ROWS来获取查询的行数,在很多分页的程序中都这样写: 复制代码 代码如下: SELECT COUNT(*) from `table` WHERE ......; 查出符合条件的记录总数: 复制代码 代码如下: SELECT * FROM

  • 一个Shell小脚本精准统计Mysql每张表的行数实现

    前言 对于开发或者运维人员来说,Mysql数据库每张表的数量肯定是要了解下,有助于我们清理无用数据或者了解哪张表比较占用空间. 另外多次统计表的行数,还能发现Mysql表的增量情况,能够预测表未来会有多大的量. 废话不多说,直接带大家写一个简单的Shell小脚本 循环获取数据库名 直接上Shell代码,show databases获取所有的库名.结果有一个我们不想要的,就是Database,这个grep -v掉,轻松获取所有数据库 [root@shijiangeit ~]# mysql -h 1

  • gorm FirstOrCreate和受影响的行数实例

    FirstOrCreate 获取第一个匹配的记录,或创建一个具有给定条件的新记录(仅适用于struct, map条件) db.Where(User{Name: "Jinzhu"}).FirstOrCreate(&user) 代码案例: func (tsu *TopicSignUp) TopicSignUpCreate() (bool, int64) { db := Db.Where(tsu).FirstOrCreate(&tsu) if err := db.Error;

  • 聊聊Navicat统计的行数竟然和表实际行数不一致的问题

    背景 近期为了保障线上数据库的稳定性,我决定针对一些大表的历史数据有计划地进行备份迁移,但是呢,发现一个奇特的现象,Navicat统计行数和表自身count统计数竟然不一致!?0.0 Navicat Navicat作为数据库管理工具,在业界广受欢迎,先甭管你电脑上现在正在运行的Navicat是正版还是盗版(你不说我也知道),不可否认的是,在我从事17年从事后端开发以来,尝试了很多同类工具,Navicat在功能上完全碾压其他数据库管理工具,尤其是细节方面,在这里不一一列举了,总之一个字,就是很好用

  • 如何利用Python快速统计文本的行数

    ​​通常我们会用wc -l来统计文件行数,不过用Python统计也很简单. 要快速统计一个文本文件中的行数,其实就是要统计这个文本文件中换行符的个数.为了尽量提高速度,我们需要尽量多读一些文本然后一起处理.统计换行符的个数可以用bytes内置的count方法. 代码如下: from __future__ import print_function import time if __name__ == '__main__': import sys start = time.time() with

  • 基于JavaScript实现动态创建表格和增加表格行数

    在工作,项目需求中,有时候表格的行数不能够满足我们的需求,这时需要我们动态的增加表格的行数,下面小编通过一段代码实例给大家介绍js创建表格和增加表格的行数的方法,并且还实现了隔行变色功能.对此感兴趣的朋友可以参考一下代码: js代码如下所示: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>动态操作表格</title> </head>

  • 自定义 DataList 显示数据行数的方法

    复制代码 代码如下: PEAEWebSiteDataContext context = new PEAEWebSiteDataContext();            var p = from n in context.tb_News                    where n.cname == "校园信息"                    select n;            var pp = p.OrderByDescending(tb_News=>tb

  • Shell脚本实现C语言代码行数统计

    写了一个比较粗糙的C语言代码行数统计脚本,目前还有些bug,而且效率也不高.脚本主要就是去除大部分的注释后统计行数,相当于做了一部分预处理的工作.下面是代码: #!/bin/bash filename=$1 echo "`whoami`" if [ $# -lt 1 ];then echo "usage : ./scripts filename" exit -1 fi if [ ! -f $filename ];then echo "$filename i

随机推荐