By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,218 Members | 1,111 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,218 IT Pros & Developers. It's quick & easy.

Double buffer error - invalid parameter used

P: n/a
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.
Nov 17 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.