zoukankan      html  css  js  c++  java
  • 支持同步滚动的RichTextbox控件

    using System.Windows.Forms;
    
    public class SynchronizedScrollRichTextBox : System.Windows.Forms.RichTextBox
    {
        public SynchronizedScrollRichTextBox Synchronized { get; set; }
        public const int WM_VSCROLL = 0x115;
        public const int EM_LINESCROLL = 0xB6;
    
        protected override void WndProc(ref System.Windows.Forms.Message msg)
        {
            if (msg.Msg == WM_VSCROLL || msg.Msg == EM_LINESCROLL)
            {
                if (Synchronized != null)
                {
                    Message message = msg;
                    message.HWnd = Synchronized.Handle;
                    Synchronized.PubWndProc(ref message);
                }
            }
            base.WndProc(ref msg);
        }
    
        public void PubWndProc(ref System.Windows.Forms.Message msg)
        {
            base.WndProc(ref msg);
        }
    }

    以上代码,复制到项目中,编译一次,拖到窗体中即可,例如拖2个实例,然后在设计界面,分别设置 Synchronized 属性为对方。运行后两个文本框就可以同步滚动。

  • 相关阅读:
    20191017-1 每周例行报告
    20191010-2 每周例行报告
    20190919-1 每周例行报告
    彭思雨20190919-3效能分析
    zipfile
    subprocess
    configparser
    hashlib
    json & pickle
    headpq
  • 原文地址:https://www.cnblogs.com/feiyuhuo/p/5987356.html
Copyright © 2011-2022 走看看