Solved

Scroll to bottom of rich text box without the flicker

Posted on 2006-06-27
9
569 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
  • 4
  • 3
9 Comments
 
LVL 62

Accepted Solution

by:
Fernando Soto earned 250 total points
Comment Utility
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
Comment Utility
Hiya,

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

Any more suggestions?

mitch
0
 
LVL 62

Expert Comment

by:Fernando Soto
Comment Utility
Can you post the code that updates the richTextBox control?
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 1

Author Comment

by:jm021196
Comment Utility
       /// <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 62

Expert Comment

by:Fernando Soto
Comment Utility
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 62

Expert Comment

by:Fernando Soto
Comment Utility
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
Comment Utility
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

728 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now