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);