Link to home
Start Free TrialLog in
Avatar of jm021196
jm021196Flag for United Kingdom of Great Britain and Northern Ireland

asked on

Scroll to bottom of rich text box without the flicker

I'm trying to create a 'text buffer' that holds about 300 lines of text.

When the buffer fills up it should chop a few lines off the top and stay scrolled to the bottom.

However everything i try creates a 'flicker' where the text box scrolls to the top, does what it has to do and scrolls to the bottom. I'm looking for this to be non jumping

(if you have ever used the program mIRC then it should act like the status window there, text appears at the bottom, scroll stays at the bottom, and the text that has overrun the max number of lines gets chopped off the top)

Any help would be apprechiated.

mitch
ASKER CERTIFIED SOLUTION
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jm021196

ASKER

Hiya,

There is a slight improvement, but really not that noticable, its still doing the jumping lots.

Any more suggestions?

mitch
Can you post the code that updates the richTextBox control?
       /// <summary>
        /// Add to the status RTB (Thread safe)
        /// </summary>
        /// <param name="statusMessage">Text to display</param>
        /// <param name="bold">bold</param>
        public void addToStatus(string statusMessage, bool bold)
        {
            if (this.rtbStatus.InvokeRequired)
            {
                SetTextCallBack d = new SetTextCallBack(addToStatus);
                this.Invoke(d, new object[] { statusMessage, bold });
            }
            else
            {
                this.rtbStatus.SuspendLayout();
                if (this.rtbStatus.Text.Length > 4096)
                {
                    this.rtbStatus.Text = this.rtbStatus.Text.Substring(this.rtbStatus.Text.IndexOf("\n"));
                }

                statusMessage = getCurrentTimeStamp() + statusMessage + "\n";
                if (bold)
                {
                    statusMessage = "=-=-==-=" + statusMessage;
                }

                this.rtbStatus.AppendText(statusMessage);


                this.rtbStatus.Focus();
                this.rtbStatus.ScrollToCaret();
                this.rtbStatus.ResumeLayout();
            }
        }
Hi jm021196;

Place the following code in the Form Load event. It will enable double buffering. This will do updates of the screen in off screen memory and when done will paint the screen all at once. This should eliminate screen flickering.

      // Setup the form for double buffering to fix screen flicker
      this.SetStyle(ControlStyles.DoubleBuffer |
            ControlStyles.UserPaint |
            ControlStyles.AllPaintingInWmPaint,
            true);
      this.UpdateStyles();
Hi Bob;

I would like to see a resolution to this question seeming I gave m021196 a solution that should have corrected the problem.

Thanks;

Fernando
Hiya,

Sorry about the late responses, I was called away on business at the last moment.

Unfortunetly FernandoSoto's answer didn't work but because he was the only person who answered and I'm not going to be around for a bit I'll award him the points.

Thanks
mitch