CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 1999
    Posts
    40

    Disable Scroll in RichTextBox

    I am creating a Syntax Highlighting Richtext box for a program I am working on. I am using the Select and SelectionColor statements to select text and change the color accordingly. Before I start doing this I disable the redraw and event events for the RTB control using SendMessage with EM_SETEVENTMASK and WM_SETREDRAW. After the highlighting is done, I enable them again.

    The issue I am having is that the auto scrolling still seems to occur when selecting text in this function. Here is the scenerio:

    I am on line 20 relative to the whole document. However, relative to the RTB display, my cursor is on the 10th line. My select statement for the highlighting ends up using the select for something on line 50 (thus scrolling the rtb down). Then I reset my cursor (using Select statement) back at line 20 (relative to whole document). The cursor is now on the 1st line relative to the RTB display (when I want it back at the 10th line).

    Is there anyway to disable the auto-scrolling that a RTB does? Or at least reset the RTB view back to the way it looked before?

    Thanks in advance...

  2. #2
    Join Date
    Nov 1999
    Posts
    40
    I still could not disable it, but here is what I did. I created a new property so that I could set where the scroll bar was before I started the highlighting, and then I would restore it after using this property. Here is the property I created. It's important to note that the property uses the Point structure.

    // --> Definitions Needed at the top <---
    [DllImport("user32.dll")]
    private static extern int SendMessage(IntPtr hwndLock,Int32 wMsg,Int32 wParam, ref Point pt);


    // *** Get / Change Scroll Position ***
    private Point RTBScrollPos
    {
    get
    {
    const int EM_GETSCROLLPOS = 0x0400 + 221;
    Point pt = new Point();

    SendMessage(this.rtbMain.Handle, EM_GETSCROLLPOS, 0, ref pt);
    return pt;
    }
    set
    {
    const int EM_SETSCROLLPOS = 0x0400 + 222;

    SendMessage(this.rtbMain.Handle, EM_SETSCROLLPOS, 0, ref value);
    }
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured