1

So I'm trying to draw a rectangle at the mouse every frame. However, I can't figure out how to clear the graphics each frame. I have tried graphics.Clear, which even using Transparent just filled my screen with a solid color. I've searched around for a bit and I couldn't find any other solution. Only other solution I was able to find was for forms using Invalidate, I am not drawing on a form.

 IntPtr desktopPtr = GetDC(IntPtr.Zero);
 Graphics g = Graphics.FromHdc(desktopPtr);
 Pen b = new Pen(Color.Red);
 g.DrawRectangle(b, new Rectangle(x, y, 25, 25));
 g.Dispose();
 ReleaseDC(IntPtr.Zero, desktopPtr);
  • You're not painting on a transparent layer above the desktop, you're painting on the actual desktop. There's no reason you should expect calling `Clear` will return the desktop to its original state, that information is gone. – Rotem Nov 28 '18 at 10:12
  • seen this: https://stackoverflow.com/questions/647270/how-to-refresh-the-windows-desktop-programmatically-i-e-f5-from-c ? – Sebastian L Nov 28 '18 at 10:24

0 Answers0