This post is for the Google archive and does not require a reply.
I received an 'Invalid parameter used' error when trying to do
double-buffering with the .Net SetStyles method. I used this code in the
constructor of my UserControl to implement double buffering:
// Enable double buffering
this.SetStyle(ControlStyles.DoubleBuffer |
ControlStyles.UserPaint |
ControlStyles.AllPaintingInWmPaint,
true);
this.UpdateStyles();
When I ran the code, I got a runtime error, 'Invalid parameter used'.
The error was caused by the fact that I explicitly disposed on the Graphics
object (grfx) to which I was drawing at the end of my drawing method in the
UserControl. I was following the conventional wisdom that says to take the
Graphics object from the onPaint event arguments, draw on it, then dispose
of it. Most of the time that's good advice. But it didn't work here, because
the CLR needed the graphics object to complete its double buffering
operation.
I removed the grfx.Dispose() call, and that fixed the problem.
David Veeneman
Foresight Systems, Inc.