zoukankan      html  css  js  c++  java
  • 如何做一个带有行数的RichTextBox

    先看下效果:

    只所以想到妖做这个,是因为目前打算写个源码生成器,为了以后编写代码方便,懒嘛!

    用用到的控件richTextBox1,richTextBox2,vScrollBar1,hScrollBar1
    不过目前下方的滚动条还未起作用,找不到方法了。再努力做吧!

    相应的代码如下;

    //========================获取行号
      int _currentLine = 0;
      public int CurrentLine
      {
       get{return _currentLine;}
       set{_currentLine = value;}
      }
      private void richTextBox1_TextChanged(object sender, System.EventArgs e)
      {
       updateNumber_Line();
      }
      private void updateNumber_Line()
      {
       Point pos = new Point(0, 0);
       int firstIndex = richTextBox1.GetCharIndexFromPosition(pos);
       int firstLine = richTextBox1.GetLineFromCharIndex(firstIndex);//=======得到行号
       pos.X = this.richTextBox1.Width;
       pos.Y = this.richTextBox1.Height;
       int lastIndex = richTextBox1.GetCharIndexFromPosition(pos);
       int lastLine = richTextBox1.GetLineFromCharIndex(lastIndex);
       int myStart = this.richTextBox1.SelectionStart;
       int myLine = this.richTextBox1.GetLineFromCharIndex(myStart) + 1;

       //============垂直滚动条
       this.vScrollBar1.Maximum = myLine;
       this.vScrollBar1.Minimum = 1;

       //============垂直滚动条
       int ViewedColumns = this.richTextBox1.Width;//===========可视列号
       this.hScrollBar1.Maximum = ViewedColumns;
       this.hScrollBar1.Minimum = 1;

       pos = richTextBox1.GetPositionFromCharIndex(lastIndex);
       if (lastIndex > _currentLine||lastIndex<_currentLine)
       {
        this.richTextBox2.Text = "";
        for (int i = firstLine; i <= lastLine + 1; i++)
        {
         this.richTextBox2.Text += i + 1 + "\n";
        }
       }
       _currentLine = lastIndex;
      }

  • 相关阅读:
    Exception in thread "main" java.lang.UnsatisfiedLinkError: xxx()V
    Python 数组比较
    远程桌面CredSSP 加密数据库修正
    (转)解决ssh登录慢的问题(一定要在远端主机上修改啊)
    让linux开机自动执行一条需要管理员的密码的命令
    ssh批量登录并执行命令(python实现)
    批量重命名文件——python实现
    配置python的eclipse开发环境
    Linux常用压缩解压命令
    强大的zsh配置文件
  • 原文地址:https://www.cnblogs.com/kingeric/p/596196.html
Copyright © 2011-2022 走看看