mastur cheef
mastur cheef

Reputation: 185

RichTextBox scrollbar flicker

I'm having an issue with a richTextBox inside of a windows form.

I have enabled vertical scrolling and everything works fine, except when I use the mouse to drag the scrollbar. When I do this, the scrollbar just stays in place and flickers until I release the drag. The bar scrolls regularly without flickering when I use the scroll wheel on my mouse, or click the up/down arrow keys.

Any ideas as to why this is happening?

Upvotes: 0

Views: 1429

Answers (1)

mastur cheef
mastur cheef

Reputation: 185

In case anyone else ever has this problem, I found a solution here: http://www.angryhacker.com/blog/archive/2010/07/21/how-to-get-rid-of-flicker-on-windows-forms-applications.aspx

Essentially, all that needs to be added to the form.cs file is:

int originalExStyle = -1;
bool enableFormLevelDoubleBuffering = true;

protected override CreateParams CreateParams
{
    get
    {
        if (originalExStyle == -1)
            originalExStyle = base.CreateParams.ExStyle;

        CreateParams cp = base.CreateParams;
        if (enableFormLevelDoubleBuffering)
            cp.ExStyle |= 0x02000000;   // WS_EX_COMPOSITED
        else
            cp.ExStyle = originalExStyle;

        return cp;
    }
}

private void TurnOffFormLevelDoubleBuffering()
{
    enableFormLevelDoubleBuffering = false;
    this.MaximizeBox = true;
}

private void frmMain_Shown(object sender, EventArgs e)
{
    TurnOffFormLevelDoubleBuffering();
}

Upvotes: 2

Related Questions