PhilH Posted August 22, 2003 Posted August 22, 2003 I have the following code in the paint event of a picturebox. Would someone please explain why the g.Dispose line raises an exception? Dim g As Graphics = e.Graphics g.DrawRectangle(Pens.Blue, New Rectangle(0, 0, 10, 10)) g.Dispose() Quote
*Experts* Nerseus Posted August 22, 2003 *Experts* Posted August 22, 2003 In the Paint event, you're given the Graphics object. In that case, you shouldn't Dispose of it since there might be other event handlers that are counting on it. Only call Dispose on a Graphics object if you create one (outside of the Paint event usually). I'm not sure why it throws an exception, but don't do it and it will go away :) -nerseus Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.