Double-Buffering Exception

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dave Veeneman

    Double-Buffering Exception

    I'm drawing a graphic directly to a form, using a Paint event handler. All
    works well, except that the graphic flickers when I resize the form. So, I
    implement double-buffering for the form using the following function:

    public void EnableDoubleBuf fering()
    {
    this.SetStyle(C ontrolStyles.Us erPaint, true);
    this.SetStyle(C ontrolStyles.Al lPaintingInWmPa int, true);
    this.SetStyle(C ontrolStyles.Do ubleBuffer, true);
    this.UpdateStyl es();
    }

    I call the function from the form's constructor, and I get an
    ArgumentExcepti on saying that an invalid parameter was used.. The call stack
    indicates the exception is thrown in the System.Drawing library.

    The code runs fine if I disable the EnableDoubleBuf fering() call, but of
    course I still have flicker.

    Am I missing something here? Any help figuring this out is much appreciated.

    Dave Veeneman
    Chicago


  • Val Savvateev

    #2
    Re: Double-Buffering Exception

    At what line are you getting the exception? I'm using double buffering in
    one of my controls too. The order is a little bit different -
    this.SetStyle(C ontrolStyles.Al lPaintingInWmPa int, true);

    this.SetStyle(C ontrolStyles.Us erPaint, true);

    this.SetStyle(C ontrolStyles.Do ubleBuffer, true);



    I think your problem is that you call UpdateStyles method (I don't) - it has
    a bit different purpose (it updates other kind of styles).



    "Dave Veeneman" <nospam@nospam. com> wrote in message
    news:O%23VIXWXV DHA.1316@TK2MSF TNGP12.phx.gbl. ..[color=blue]
    > I'm drawing a graphic directly to a form, using a Paint event handler. All
    > works well, except that the graphic flickers when I resize the form. So, I
    > implement double-buffering for the form using the following function:
    >
    > public void EnableDoubleBuf fering()
    > {
    > this.SetStyle(C ontrolStyles.Us erPaint, true);
    > this.SetStyle(C ontrolStyles.Al lPaintingInWmPa int, true);
    > this.SetStyle(C ontrolStyles.Do ubleBuffer, true);
    > this.UpdateStyl es();
    > }
    >
    > I call the function from the form's constructor, and I get an
    > ArgumentExcepti on saying that an invalid parameter was used.. The call[/color]
    stack[color=blue]
    > indicates the exception is thrown in the System.Drawing library.
    >
    > The code runs fine if I disable the EnableDoubleBuf fering() call, but of
    > course I still have flicker.
    >
    > Am I missing something here? Any help figuring this out is much[/color]
    appreciated.[color=blue]
    >
    > Dave Veeneman
    > Chicago
    >
    >[/color]


    Comment

    • Dave Veeneman

      #3
      Re: Double-Buffering Exception

      Thanks! I'll give that a try.

      For the benefit of anyone else reading this posting-- the code I originally
      used came from the DotNet SDK documentation, which means the example in that
      documentation may not work correctly.

      --
      Dave Veeneman
      Chicago


      Comment

      • Piers Lawson

        #4
        Double-Buffering Exception

        Did you ever find a solution? I get the same exception,
        though I'm using slightly different styles:

        DoubleBuffer, AllPaintingInWm Paint, UserPaint, Opaque
        ResizeRedraw.

        I get the exception:

        System.Argument Exception: Invalid parameter used.

        By dropping the AllPaintingInWm Paint the problem went
        away, but of course my flicker returns.

        Piers

        Comment

        • Piers Lawson

          #5
          Double-Buffering Exception

          I just looked through the call exception stack and noticed
          Dispose was in there. At the end of my OnPaint method I
          have been calling e.Graphics.Disp ose(). I removed this
          line an evrything started working!

          I guess with double buffering on you shouldn't Dispose of
          the graphics surface?

          Piers

          Comment

          • Dave Veeneman

            #6
            Re: Double-Buffering Exception

            Isn't that odd? Thanks!

            "Piers Lawson" <PiersDROPTHIS@ gibber.freeserv e.co.uk> wrote in message
            news:5ad401c357 6c$8c262360$a00 1280a@phx.gbl.. .[color=blue]
            > I just looked through the call exception stack and noticed
            > Dispose was in there. At the end of my OnPaint method I
            > have been calling e.Graphics.Disp ose(). I removed this
            > line an evrything started working!
            >
            > I guess with double buffering on you shouldn't Dispose of
            > the graphics surface?
            >
            > Piers[/color]


            Comment

            • Dave Veeneman

              #7
              Re: Double-Buffering Exception

              Isn't that odd? Thanks!

              "Piers Lawson" <PiersDROPTHIS@ gibber.freeserv e.co.uk> wrote in message
              news:5ad401c357 6c$8c262360$a00 1280a@phx.gbl.. .[color=blue]
              > I just looked through the call exception stack and noticed
              > Dispose was in there. At the end of my OnPaint method I
              > have been calling e.Graphics.Disp ose(). I removed this
              > line an evrything started working!
              >
              > I guess with double buffering on you shouldn't Dispose of
              > the graphics surface?
              >
              > Piers[/color]


              Comment

              Working...