![](/img/trans.png)
[英]How to synchronize wpf richtextbox vertical scrolling with split container Panel2
[英]Synchronize richtextbox scrolling in winforms
我使用了以下方法
滾動兩個richtextbox,我結束了以下內容,只是稱為rtb1.BindScroll(rtb2)
這行得通,但是否可以同時為這兩個鼠標器配套? 另外,向上和向下翻頁也很好。
此方法承諾可以使用鼠標,但根本無法使用http://social.msdn.microsoft.com/Forums/windows/en-US/161d1636-aea3-4fee-beb4-52370663d44c/synchronize-scrolling-in-2-richtextboxes -in-C?論壇=的WinForms
[DebuggerNonUserCode]
public class RouterRichTextBox : RichTextBox
{
public delegate void vScrollEventHandler(Message message);
public const int WM_VSCROLL = 0x115;
public event vScrollEventHandler vScroll;
private List<RouterRichTextBox> peers = new List<RouterRichTextBox>();
public void BindScroll(RouterRichTextBox arg)
{
if (peers.Contains(arg) || arg == this)
return;
peers.Add(arg);
arg.BindScroll(this);
}
private void DirectWndProc(ref Message m)
{
base.WndProc(ref m);
}
protected override void WndProc(ref Message m)
{
if (m.Msg == WM_VSCROLL)
{
foreach (RouterRichTextBox peer in peers)
{
Message peerMessage = Message.Create(peer.Handle, m.Msg, m.WParam, m.LParam);
peer.DirectWndProc(ref peerMessage);
}
}
base.WndProc(ref m);
}
}
對鼠標滾輪的支持應通過添加來啟用
private const int WM_MOUSEWHEEL = 0x20a;
上你的課。 在WndProc中將此添加到if子句中
if (m.Msg == WM_VSCROLL || m.Msg == WM_MOUSEWHEEL)
啟用鼠標滾輪的使用。 我剛剛對其進行了測試,並且在這里可以正常工作。
為了使用PageUp或PageDown,您必須進一步研究。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.