Click here to Skip to main content
12,621,744 members (37,817 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

16.2K views
10 bookmarked
Posted

Synchronized RichTextBox objects (or how to scroll 2 RichTextBox objects together)

, 22 May 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
In this tip, I will show how to scroll two RichTextBox objects together
In my previous post (Synchronized ListBox objects (or how to scroll 2 ListBox objects together)[^]), I described how to create synchronized (or linked) ListBox and ListView objects. Now I continue investigation in this area and I have found another interesting example which describes synchronization of two RichTextBox objects. The first step is to create a class which derives from RichTextBox class.
public class SynchronizedScrollRichTextBox : System.Windows.Forms.RichTextBox
{
    public event vScrollEventHandler vScroll;
    public delegate void vScrollEventHandler(System.Windows.Forms.Message message);
 
    public const int WM_VSCROLL = 0x115;
 
    protected override void WndProc(ref System.Windows.Forms.Message msg)
    {
        if (msg.Msg == WM_VSCROLL)
        {
            if (vScroll != null)
            {
                vScroll(msg);
            }
        }
        base.WndProc(ref msg);
    }
 
    public void PubWndProc(ref System.Windows.Forms.Message msg)
    {
        base.WndProc(ref msg);
    }
}
I created two SynchronizedScrollRichTextBox controls and placed them on the form. Then, I added the following code (vScroll event):
private void synchronizedScrollRichTextBox1_vScroll(Message message)
{
    message.HWnd = synchronizedScrollRichTextBox2.Handle;
    synchronizedScrollRichTextBox2.PubWndProc(ref message);
}

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Kanasz Robert
Architect The Staffing Edge & Marwin Cassovia Soft
Slovakia Slovakia
My name is Robert Kanasz and I have been working with ASP.NET, WinForms and C# for several years.
MCSD - Web Applications
MCSE - Data Platform
MCPD - ASP.NET Developer 3.5
- Web Developer 4
MCITP - Database Administrator 2008
- Database Developer 2008
MCSA - SQL Server 2012
MCTS - .NET Framework 3.5, ASP.NET Applications
- SQL Server 2008, Database Development
- SQL Server 2008, Implementation and Maintenance
- .NET Framework 4, Data Access
- .NET Framework 4, Service Communication Applications
- .NET Framework 4, Web Applications
MS - Programming in HTML5 with JavaScript and CSS3 Specialist

Open source projects: DBScripter - Library for scripting SQL Server database objects


Please, do not forget vote

You may also be interested in...

Pro
Pro

Comments and Discussions

 
GeneralExcellent! Pin
Jeff Schnarel5-Dec-14 10:29
memberJeff Schnarel5-Dec-14 10:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.161128.1 | Last Updated 22 May 2011
Article Copyright 2011 by Kanasz Robert
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid