Results 1 to 3 of 3

Thread: Repaint without flickering

  1. #1

    Thread Starter
    Hyperactive Member vbcode1980's Avatar
    Join Date
    Nov 2005
    Location
    Anywhere the wind blows
    Posts
    365

    Repaint without flickering

    Hi,

    I have a form with a background image, and I use System.Drawing.Graphics.DrawString() to draw text on the form.

    That works fine.
    Now all I need is a way to refresh the screen when the text has been changed.
    I've tried this.Refresh() and this.Invalidate() but they produce a flicker, because the entire screen is repainted.

    is there a way to clear and repaint only the text, without having to repaint the background image as well?
    I code C#....

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Repaint without flickering

    In actual fact, Invalidate does NOT force the form to repaint. All it does is invalidate part of the form so that it will be repainted next time a repaint is done. To ensure that any repainting is done immediately after calling Invalidate you must call Update. Here's what the Refresh method looks like:
    C# Code:
    1. public virtual void Refresh()
    2. {
    3.     this.Invalidate(true);
    4.     this.Update();
    5. }
    You have two choices to speed things up and both involve calling Invalidate followed by Update.

    When you call Refresh it calls Invalidate and passes True, which forces all child controls to repaint too. You can call Invalidate explicitly and pass False, so only the form and not any child controls will be repainted.

    Even better would be if you calculated the smallest Rectangle or Region that contained your text and then passed that as a parameter to Invalidate. That way only the area containing the text will be invalidated so only that area will be repainted when you call Update.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Hyperactive Member vbcode1980's Avatar
    Join Date
    Nov 2005
    Location
    Anywhere the wind blows
    Posts
    365

    Re: Repaint without flickering

    Cheers!
    I'll try that when I get home.
    I code C#....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width