Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. DoubleBuffer problem ..

DoubleBuffer problem ..

Scheduled Pinned Locked Moved C#
helpgraphics
9 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Sharpoverride
    wrote on last edited by
    #1

    whenever i use setstyle( ... ) ; and in my paint function i do something like void paintMethod( .., .. ) { using( Graphics g = e.Graphics ) { g.doesSomeDrawing(); } } the ... statements replace the actual code wich is corect i am getting an error message saying "Additional information: Invalid parameter used." and if i don't use the using statement everything works fine .. no error message !:omg: Lazar Mihai Elev clasa XI C Grup Scolar Sanitar

    G D S 3 Replies Last reply
    0
    • S Sharpoverride

      whenever i use setstyle( ... ) ; and in my paint function i do something like void paintMethod( .., .. ) { using( Graphics g = e.Graphics ) { g.doesSomeDrawing(); } } the ... statements replace the actual code wich is corect i am getting an error message saying "Additional information: Invalid parameter used." and if i don't use the using statement everything works fine .. no error message !:omg: Lazar Mihai Elev clasa XI C Grup Scolar Sanitar

      G Offline
      G Offline
      Gary Thom
      wrote on last edited by
      #2

      I suspect it is the using you are copying an existing Graphics object, not assigning a new one. Gary In Scotland, there is no such thing as bad weather - only the wrong clothes. - Billy Connolly

      1 Reply Last reply
      0
      • S Sharpoverride

        whenever i use setstyle( ... ) ; and in my paint function i do something like void paintMethod( .., .. ) { using( Graphics g = e.Graphics ) { g.doesSomeDrawing(); } } the ... statements replace the actual code wich is corect i am getting an error message saying "Additional information: Invalid parameter used." and if i don't use the using statement everything works fine .. no error message !:omg: Lazar Mihai Elev clasa XI C Grup Scolar Sanitar

        D Offline
        D Offline
        Dave Kreskowiak
        wrote on last edited by
        #3

        You can either not use the using statement, safely, or you can try something like this:

        Graphics g = e.Graphics;
        using ( g )
        {
            g.doesSomeDrawing();
        }
        

        RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

        H 1 Reply Last reply
        0
        • S Sharpoverride

          whenever i use setstyle( ... ) ; and in my paint function i do something like void paintMethod( .., .. ) { using( Graphics g = e.Graphics ) { g.doesSomeDrawing(); } } the ... statements replace the actual code wich is corect i am getting an error message saying "Additional information: Invalid parameter used." and if i don't use the using statement everything works fine .. no error message !:omg: Lazar Mihai Elev clasa XI C Grup Scolar Sanitar

          S Offline
          S Offline
          Skynyrd
          wrote on last edited by
          #4

          The answer is simple. The using statement resolves to the following code: try { g.doesSomeDrawing(); } finally { g.Dispose(); } U are disposing a graphics object that u dont "own" (e.graphics). On a general basis you should only dispose graphic objects that you explicitly create through the Control's CreateGraphics() method or through a New Graphics() statement;

          S 1 Reply Last reply
          0
          • D Dave Kreskowiak

            You can either not use the using statement, safely, or you can try something like this:

            Graphics g = e.Graphics;
            using ( g )
            {
                g.doesSomeDrawing();
            }
            

            RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

            H Offline
            H Offline
            Heath Stewart
            wrote on last edited by
            #5

            The actual exception is because the caller of OnPaint (most often WndProc) is trying to dispose the Graphics object and it's already been disposed. He should not be using using at all. This posting is provided "AS IS" with no warranties, and confers no rights. Software Design Engineer Developer Division Sustained Engineering Microsoft [My Articles] [My Blog]

            D 1 Reply Last reply
            0
            • H Heath Stewart

              The actual exception is because the caller of OnPaint (most often WndProc) is trying to dispose the Graphics object and it's already been disposed. He should not be using using at all. This posting is provided "AS IS" with no warranties, and confers no rights. Software Design Engineer Developer Division Sustained Engineering Microsoft [My Articles] [My Blog]

              D Offline
              D Offline
              Dave Kreskowiak
              wrote on last edited by
              #6

              I thought it might be something along those lines, wasn't sure though. Too drugged up to think about it and no VS.NET at work to test it with. 8( Let me tell you, life sucks without a compiler at fingertips! RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

              H 1 Reply Last reply
              0
              • D Dave Kreskowiak

                I thought it might be something along those lines, wasn't sure though. Too drugged up to think about it and no VS.NET at work to test it with. 8( Let me tell you, life sucks without a compiler at fingertips! RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

                H Offline
                H Offline
                Heath Stewart
                wrote on last edited by
                #7

                I didn't have a compiler. :) Basically, if you didn't alloc it then you don't free it. In native APIs this isn't always the case, though, since some APIs alloc memory and expect the caller to free it. Such APIs should always document such a requirement. This posting is provided "AS IS" with no warranties, and confers no rights. Software Design Engineer Developer Division Sustained Engineering Microsoft [My Articles] [My Blog]

                D 1 Reply Last reply
                0
                • H Heath Stewart

                  I didn't have a compiler. :) Basically, if you didn't alloc it then you don't free it. In native APIs this isn't always the case, though, since some APIs alloc memory and expect the caller to free it. Such APIs should always document such a requirement. This posting is provided "AS IS" with no warranties, and confers no rights. Software Design Engineer Developer Division Sustained Engineering Microsoft [My Articles] [My Blog]

                  D Offline
                  D Offline
                  Dave Kreskowiak
                  wrote on last edited by
                  #8

                  Heath Stewart wrote: Basically, if you didn't alloc it then you don't free it. In native APIs this isn't always the case, I've run into that many a time. :-D I just wanted to try it before I stuck my foot in my mouth. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

                  1 Reply Last reply
                  0
                  • S Skynyrd

                    The answer is simple. The using statement resolves to the following code: try { g.doesSomeDrawing(); } finally { g.Dispose(); } U are disposing a graphics object that u dont "own" (e.graphics). On a general basis you should only dispose graphic objects that you explicitly create through the Control's CreateGraphics() method or through a New Graphics() statement;

                    S Offline
                    S Offline
                    Sharpoverride
                    wrote on last edited by
                    #9

                    Thanks.. I get it now.. U've all been of great help Lazar Mihai The road to becoming a good programmer is paved with bad scripts !

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups