3

私はwinforms4(customRTB1とcustomRTB2)で2つのリッチテキストボックスを使用しています。両方のrtbのテキストは同じです。私が達成したいのは、一方のrtb(customRTB1)を下にスクロールすると、もう一方のrtb(customRTB2)もcustomRTB1とまったく同じ位置にスクロールする必要があるということです。私はこれを試みました:

public class CustomRTB : RichTextBox
    {
        #region API Stuff
        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        public static extern int GetScrollPos(IntPtr hWnd, int nBar);

        [DllImport("user32.dll")]
        public static extern int SetScrollPos(IntPtr hWnd, int nBar, int nPos, bool bRedraw);

        private const int SB_HORZ = 0x0;
        private const int SB_VERT = 0x1;
        #endregion
        public int HorizontalPosition
        {
            get { return GetScrollPos((IntPtr)this.Handle, SB_HORZ); }
            set { SetScrollPos((IntPtr)this.Handle, SB_HORZ, value, true); }
        }

        public int VerticalPosition
        {
            get { return GetScrollPos((IntPtr)this.Handle, SB_VERT); }
            set { SetScrollPos((IntPtr)this.Handle, SB_VERT, value, true); }
        }
    }

水平位置と垂直位置を使用して、2番目のrtbのスクロールバーを次のように移動できます。

private void customRTB1_VScroll(object sender, EventArgs e)
{
          customRTB2.VerticalPosition = customRTB1.VerticalPosition;
}

これにより、2番目のrtbのスクロールバーが最初のrtbの位置に移動しますが、テキストはまったく移動しません。では、この2番目のrtbを作成して、スクロールバーの位置に従って対応するテキストを表示するにはどうすればよいでしょうか。主に、最初のrtbで発生するすべてのアクティビティ(編集、スクロールなど)を2番目のrtbで繰り返すようにします。私は解決策に非常に近いことを知っています。助けてください。

4

0 に答える 0