Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Switching top-most form without flickering

Tags:

c#

.net

c#-4.0

I'm developing a magnifier in C# .NET (using WindowsForm) that shows a top-most click-able through form. This top-most window shows an specific part of the screen.

The problem I'm having is that to take the screenshot I need to Hide() and Show() the form (otherwise I would take a screenshot of the magnifier) and this creates an annoying flickering in which the magnifier disappears and rapidly appears again.

How could I take a screenshot of the Desktop without hiding/showing the form? Is there another approach/workaround?

Thanks.

like image 849
adelriosantiago Avatar asked Oct 22 '22 07:10

adelriosantiago


1 Answers

Use the form's Opacity property. Set it to 99% in the designer. When you are ready to take the screen shot, set it to 0, make the shot and set it back to 0.99.

The change is instant, no need to wait and no flicker or repainting. Do not restore it to 1.0, that flickers.

Do beware that you remove the "Hall of Mirrors" effect from the magnifier. Bit of a loss :)

like image 183
Hans Passant Avatar answered Oct 24 '22 12:10

Hans Passant