   [.net] Clearing the Graphics Buffer
  I know in C# there exists a function Clear(Color c) for the graphics object. However, this method doesn't really clear the graphics on screen, all it really does is the FillRectangle function with a specified color for the length and width of the entire screen. What I want is something that truly clears out the screen, not some sort of mask to cover what was previously drawn. In my search I've found nothing on this topic, however, I have discovered something interesting that I think would helpful for this problem. Try this experiment:Create a windows application project in VS and add a panel to the form. Within the panel, make it so that it has a Rectangle, let's call it rect. Now, make it so that if you press any of the arrow keys on the keyboard it will Offset rect's position and refresh the panel so that you can see it moved. And now this is the most important step, in your paint method for the panel, DO NOT use g.clear or g.FillRectangle to paint over what was previously drawn, instead all you should do is g.FillRectangle using the bounds of rect.When you run this application what you should see (and expect) is that rect is drawn and filled within the panel but when you move rect using the arrow keys it doesn't erase anything that was drawn previously, and instead all you will see is sort of a thick line that keeps extending into the direction given by the arrow key you pressed.However, this is where the interesting part comes in, minimize the form and then maximize it. You should notice that what previously looked like a really thick line has vanished and all you see is the filled in rectangle of rect, it's as if you had ran this application for the first time.Now, obviously I hadn't specified anywhere in the code to clear anything on the panel. So, then it must be that, when you minimize a form it clears out its own internal graphics buffer, and it clears in the exact way I want (not by "masking" what was previously drawn). So this elusive functionality that I've been searching for within c# to clear out the graphics does exist. Yet,even so, I still do not know how to do it. So, I ask, would any of you care to comment on this issue, do you know what functions are called when a c# form is minimized (the answers may lie in there)?Any help is greatly appreciated.Thanks,Tamir   
  When an Windows application is loses the device, you must reset it to regain the textures lost. You must account for this in you application in case a user presses the Windows key, Al+tab, or the Application is Minimized while in full screen mode. This will also happen if another application using DirectX or OpenGL takes 'control' of the graphics card. Usually once the device is lost, you must reload resources such as textures since they no longer are in the graphics cards memory. These effects can also happen while in windowed mode as well.Why do you want to destroy all of the memory in the screen buffers? What benefit over just filling the screen by callign clear would it give you. If you don't want your 3D stuff to redraw after an call to the Clear(..) method, then add some logic to not call your RenderPrimitive, etc functions.It sounds like you are using your application in Windows mode. I believe that the effect you are seeing is being caused by the way the .NET Panel redraws itself and not exactly DirectX.   ;Quote:Why do you want to destroy all of the memory in the screen buffers? What benefit over just filling the screen by callign clear would it give you. If you don't want your 3D stuff to redraw after an call to the Clear(..) method, then add some logic to not call your RenderPrimitive, etc functions.The reason I want to destroy all of the memory in the screen buffers is because it's really useful when you are trying to have transparent panel. Since, if you have a transparent background you can't just clear it out by filling a rectangle over the length and width of the panel (that would defeat the purpose of it being transparent).Quote:It sounds like you are using your application in Windows mode. I believe that the effect you are seeing is being caused by the way the .NET Panel redraws itself and not exactly DirectX.Sorry if I made it seem like I was using DirectX, I'm actually just using the .NET panel and GDI+. Anonymous, do you know how one would destroy the memory in the screen buffers in my situation? I think that would solve the problem, thanks.   ;  Simple: You can't.WinForms is a lightweight wrapper around the standard Win32 interface. This means, that everything is owned by Windows itself, and WinForms just wraps the HANDLE to the object with a bunch of functions and some other information.The behaviour described in your initial post is simple standard Win32 behaviour: If you don't clear the panel yourself, nothing happens. You continue to add more information to a Windows owned bitmap.I believe there are ways in Windows to make windows(or in this case, controls) OPAQUE. With this setting, the panel or object should be transparant.Toolmaker   ;  Your post doesn't really make sense.  There is no masking or composition going on, you app is drawing directly to the screen.  Pixels only have one color.When you say "clear" what I *think* you are trying to say is that you want to force all the windows in a specified rectangle to redraw themselves.  This matches what the system does in your minimize/restore scenario.  In straight GDI this is done via InvalidateRect/UpdateWindow or possibly RedrawWindow.  I don't know how it's done in C#.   