same scroll bar for two richtextboxes

自闭症网瘾萝莉.ら 提交于 2019-12-10 16:02:14

问题


Is there any third party tool available which has two richtextboxes but only a shared scroll bar for both. I need to implement some text in two different languages but both the textboxes should scroll at the same time.


回答1:


    public enum ScrollBarType : uint
    {
        SbHorz = 0,
        SbVert = 1,
        SbCtl = 2,
        SbBoth = 3
    }

    public enum Message : uint
    {
        WM_VSCROLL = 0x0115
    }

    public enum ScrollBarCommands : uint
    {
        SB_THUMBPOSITION = 4
    }

    [DllImport("User32.dll")]
    public extern static int GetScrollPos(IntPtr hWnd, int nBar);

    [DllImport("User32.dll")]
    public extern static int SendMessage(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam);
   // Set the dual scrolling on the richTextbox1 and affects richTextbox2

    private void richTextBox1_VScroll(object sender, EventArgs e)
    {
        int nPos = GetScrollPos(richTextBox1.Handle, (int)ScrollBarType.SbVert); 
        nPos <<= 16;
        uint wParam = (uint)ScrollBarCommands.SB_THUMBPOSITION | (uint)nPos;
        SendMessage(richTextBox2.Handle, (int)Message.WM_VSCROLL, new IntPtr(wParam), new IntPtr(0));
    }


来源:https://stackoverflow.com/questions/10266625/same-scroll-bar-for-two-richtextboxes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!