Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6933505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:50:27+00:00 2026-05-27T11:50:27+00:00

I am a bit confused: We have a chat application that has a requirement

  • 0

I am a bit confused:

We have a chat application that has a requirement to NOT scroll chat, if the user is scrolled up; and we have a scrollInfo class that provides us with the ability to check if the scroll bar thumb is at the bottom of the scrollbar, so that we can identify if we should scroll or not.

Unfortunately, there are many different ways to scroll chat. One could use the scrollbars up/down boxes, or the scrollbar thumb, or just scroll using the mouse wheel.

However, if the up/down arrows are used, we have no issue.

And, if the scrollbar thumb is used, the VScroll event does fire, but we have no way of identifying which DIRECTION the thumb is moved, or how to check if it’s being held down, without using a timer to constantly query the left mouse button status.

And, lastly, if mousewheel is scrolled, while we can tell which direction it’s going by looking at the Delta property, the VScroll event still fires after the Mouse Wheel event is handled. So, we essentially have a duplicate scroll happen.

I need some help with this. Our chat application is as follows:

  • .NET 4.0 Windows Forms C# Application
  • Built in Visual Studio 2010
  • *Chat Output: * RichTextBox that auto formats text entering it.

Here’s an example of our logic, that just isn’t working:

  1. User Scrolls Up using Mouse wheel: When new messages come in, they should NOT scroll the chat output box back down. Instead, when a scroll event happens, it should be able to detect where the scroll thumb is, and make that determination.

  2. User Scrolls up using the ScrollBar thumb: VScroll event is fired, which checks if the scrollbar is at the ‘bottom’ of the scroll box. And, if it is, it does the full scroll event, to ensure that the caret is always placed at the end of the scroll box, and is hidden (so that the READ ONLY chat ouput, has no actual blinking I beam).

  3. User scrolls using the scrollbar up/down arrows: works just fine. (no need to explain this one, as it’s already working).

I need some clarification here, how can i properly check these events?

——– EDIT FOR CLARIFICATION ———
Contents of scrollInfo class:

 internal class Scrollinfo
{
    internal const uint ObjidVscroll = 0xFFFFFFFB;

    [DllImport("user32.dll", SetLastError = true, EntryPoint = "GetScrollBarInfo")]
    private static extern int GetScrollBarInfo(IntPtr hWnd,
                                               uint idObject,
                                               ref Scrollbarinfo psbi);

    internal static bool CheckBottom(Control rtb, int postion)
    {
        var info = new Scrollbarinfo();
        info.CbSize = Marshal.SizeOf(info);

        var chk = GetScrollBarInfo(rtb.Handle,
                                   ObjidVscroll,
                                   ref info);
        if (chk == 0)
            GetScrollBarInfo(rtb.Handle,
                             ObjidVscroll,
                             ref info);


        bool isbottom = info.XyThumbBottom
                        >= (info.RcScrollBar.Bottom - info.RcScrollBar.Top - (info.DxyLineButton + 1));
        if (info.DxyLineButton <= 0) isbottom = true;
        if (info.XyThumbBottom <= 0) isbottom = true;
        return isbottom;
    }


}

internal struct Scrollbarinfo
{
    internal int CbSize;
    internal Rect RcScrollBar;
    internal int DxyLineButton;
    internal int XyThumbTop;
    internal int XyThumbBottom;
    internal int Reserved;
    [MarshalAs(UnmanagedType.ByValArray, SizeConst = 6)]
    internal int[] Rgstate;
}

internal struct Rect
{
    internal int Left;
    internal int Top;
    internal int Right;
    internal int Bottom;
}}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T11:50:28+00:00Added an answer on May 27, 2026 at 11:50 am

    You could try something like this:

    Update the box with the new text to be displayed and then find the last visible line using the following code:

    rtb.GetLineFromCharIndex(rtb.GetCharIndexFromPosition(new Point(rtb.Width, rtb.Height)));
    

    Now next time that you need to put text into the RichTextBox, just check for the last visible line using the same code as above.

    If the new last visible line is less than the older one, it means the user has scrolled upwards (or the RichTextBox has been resized). In either case, you’ll just have to move the caret to the end of the text and then call the RichTextBox.ScrollToCaret() method to restore the position.

    I also recommend you take a look at the following on the MSDN site:

    • RichTextBox Methods
    • RichTextBox.GetCharIndexFromPosition Method
    • RichTextBox.GetLineFromCharIndex Method
    • RichTextBox.Select Method¹
    • RichTextBox.ScrollToCaret Method

    ¹ This can be used to set the caret position.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm a little bit confused by this scenario: I have a class that implements
I am a bit confused about this. I have an R package that has
I'm a bit confused: I have a function, that takes an Object as argument.
I am a bit confused and need your help. I have a database that
I am a bit confused over what is happening. I have my application using
Ok, i'm a bit confused. I am working on a project that have to
I am bit confused I have a snippet on domainevents where ` public class
I'm a little bit confused here. I have 2 models: User Ticket A Ticket
We have a generated XML schema that I am a bit confused on the
I'm a bit confused. I have the following code: public class MyClass { public

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.