Skip to content

Instantly share code, notes, and snippets.

@jkingry
Created September 23, 2010 15:34
Show Gist options
  • Save jkingry/593809 to your computer and use it in GitHub Desktop.
Save jkingry/593809 to your computer and use it in GitHub Desktop.
// http://stackoverflow.com/questions/3322741/synchronizing-multiline-textbox-positions-in-c/3779949#3779949
namespace Kingry.StackOverFlow.Question_3779949
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
class TextBoxSynchronizedScroll : TextBox
{
public const int WM_VSCROLL = 0x115;
List<TextBoxSynchronizedScroll> peers = new List<TextBoxSynchronizedScroll>();
public void AddPeer(TextBoxSynchronizedScroll peer)
{
this.peers.Add(peer);
}
private void DirectWndProc(ref Message m)
{
base.WndProc(ref m);
}
protected override void WndProc(ref Message m)
{
if (m.Msg == WM_VSCROLL)
{
foreach (var peer in this.peers)
{
var peerMessage = Message.Create(peer.Handle, m.Msg, m.WParam, m.LParam);
peer.DirectWndProc(ref peerMessage);
}
}
base.WndProc(ref m);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment