Solved

Scroll to bottom of rich text box without the flicker

Posted on 2006-06-27
9
575 Views
Last Modified: 2007-12-19
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
0
Comment
Question by:jm021196
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
9 Comments
 
LVL 63

Accepted Solution

by:
Fernando Soto earned 250 total points
ID: 16995336
Hi jm021196;

Before updating the RichTextBox do a .SuspendLayout

    richTextBox1.SuspendLayout();

and after you finished updating the control do a ResumeLayout

    richTextBox1.ResumeLayout();

Fernando
0
 
LVL 1

Author Comment

by:jm021196
ID: 16995789
Hiya,

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

Any more suggestions?

mitch
0
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 16995882
Can you post the code that updates the richTextBox control?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:jm021196
ID: 16995951
       /// <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();
            }
        }
0
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 16996262
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();
0
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 17142808
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
0
 
LVL 1

Author Comment

by:jm021196
ID: 17160945
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
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question