Hi there fellow coders!
I've ran into a GDI+ problem. I'm coding C# on .NET Framework 3.5. The problem I'm having is slow response in my application when drawing with my own-developed graphics tools. I'm drawing via the MouseMove events of a Control and the CreateGraphics() method on the Control, but first on my doublebuffer Image. It works great when I use the tools on small rectangles but when I increase the size the drawing goes down in fps to less than 1, using 2 screens on my computer.
What is the proper way to draw like im trying to do? I've tried Invalidate methods to improve performance with no luck. The problem if of course less when not doublebuffering, but then it is flickering and I get other problems like erasing the temporary rectangle when drawing so it don't leaves traces.
This is a video I made of the problem.
The quality isn't that good but you can still see the problem quite clear, the drawing is always behind the mouse, not like in other programs where the drawing seems instant.
Im sorry, I've tried your solutions but it still is slow in response. I made a small testform to try this and even that suffers from this problem I'm having. Neither of you mentioned how to make the drawing happen so I assumed via Invalidate() ?
Here is the code:
public partial class Form1 : Form
Point down = Point.Empty;
Point now = Point.Empty;
Pen b = Pens.Black.Clone() as Pen;
protected override void OnPaint(PaintEventArgs e)
if (down != Point.Empty)
e.Graphics.DrawRectangle(b, down.X, down.Y, now.X - down.X, now.Y - down.Y);
private void Form1_MouseDown(object sender, MouseEventArgs e)
down = e.Location;
private void Form1_MouseUp(object sender, MouseEventArgs e)
down = Point.Empty;
private void Form1_MouseMove(object sender, MouseEventArgs e)
now = e.Location;
if(down != Point.Empty)
When the form is small, the response is ok, but when enlarged it goes bananas. My next thought on this is, is it even possible to get it better than this without moving on to XNA or something else with acceleration?
Appreciate your efforts and tips very much, and the fast responds!