How can I sync the scrolling of two multiline textboxes?

后端 未结 5 473
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-30 07:57

How can I sync the scrolling of two multiline textboxes in C# (WinForms)?

When you scroll up/down a line in TextBox A, TextBox B should scroll up/down too. The same

5条回答
  •  星月不相逢
    2020-11-30 08:39

    Hans Passant's solution worked like a charm but I needed a RichTextBox with both horizontal and vertical scrollbars. If you extend a RichTextBox instead of a TextBox you'll need to change the ScrollBars property accordingly (I used RichTextBoxScrollBars.Both).

    If you want to sync horizontal scrolling as well, look for (m.Msg == 0x115) || (m.Msg == 0x114).

提交回复
热议问题