I wanted to synch scrolling of ListView and TextBox, I did found how to synch two ListViews Scrolling list view when another list view is scrolled and also how to do the trick for two TextBox controls How can I sync the scrolling of two multiline textboxes?
Using tips from these topics i've got half way through, for now i've only managed to ScrollSycnhedListView scrolling to affect ScrollSycnhedTextBox scrolling but no other way around.
Ofcourse I did checked twice if Buddy value of my controls points one to another, unfortunately issue isn't that simple, here is code of my controls.
ScrollSycnhedListView
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace MyApp
{
public partial class ScrollSynchListView :ListView {
public ScrollSynchListView() {}
public Control Buddy { get; set; }
private static bool scrolling; // In case buddy tries to scroll us
protected override void WndProc(ref Message m) {
base.WndProc(ref m);
// Trap WM_VSCROLL message and pass to buddy
if ((m.Msg == 0x115 || m.Msg == 0x20a) && !scrolling && Buddy != null && Buddy.IsHandleCreated)
{
scrolling = true;
SendMessage(Buddy.Handle, m.Msg, m.WParam, m.LParam);
scrolling = false;
}
}
[DllImport("user32.dll", CharSet = CharSet.Auto)]
private static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wp, IntPtr lp);
}
}
ScrollSycnhedTextBox
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace MyApp
{
public partial class ScrollSynchTextBox :TextBox {
public ScrollSynchTextBox() {}
public Control Buddy { get; set; }
private static bool scrolling; // In case buddy tries to scroll us
protected override void WndProc(ref Message m) {
base.WndProc(ref m);
// Trap WM_VSCROLL message and pass to buddy
if ((m.Msg == 0x115 || m.Msg == 0x20a) && !scrolling && Buddy != null && Buddy.IsHandleCreated)
{
scrolling = true;
SendMessage(Buddy.Handle, m.Msg, m.WParam, m.LParam);
scrolling = false;
}
}
[DllImport("user32.dll", CharSet = CharSet.Auto)]
private static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wp, IntPtr lp);
}
}
I want to ask if it's possible to synch two controls of different types? What i should change in my code to get the result i want?