Fredd
Fredd

Reputation: 1

WinForm C# : How to prevent Snipping tool or Snip & Sketch tool to capture screen shot of the particular child window?

I would like to prevent capturing screen using snipping tools. I've already prevented Print Screen by registering KeyUp event and clearing clipboard. I would like to prevent capturing screen only for particular Child Form (Popup Dialog).

I tried Form Deactivate event but as soon as user click on Snipping tool's New Snip function, it activates my application.

Edit

I found a gimmick. Please note that neither it's bulletproof solution nor its good User Experience but it might be helpful for some of you out there.

Steps

  1. Take panel, set background color property to gray (or any of your choice).
  2. Make sure that panel is hidden and it's SendToBack.
  3. Register panel's click event.
  4. Register Form Deactivate event.
  5. On Form Deactivate, set that panel's visibility to true, dock it to fill screen and set BringToFront. So when user switch to other application or click anywhere outside the app, grayed out panel will cover your actual screen.
  6. When user switch back to the application, make them click on panel to reopen (unhide) your actual screen.

Again, as I said this is gimmick and not good User Experience but it might help someone like me whose main objective is to prevent users from taking screen shot of sensitive data.

User can still take picture using their phone or camera or screenshot VM by running your application in VM. So my solution is not bulletproof but at least it will definitely make it not so easy.

Cheers!!

Upvotes: 0

Views: 1011

Answers (1)

JonasH
JonasH

Reputation: 36391

Use pInvoke to call SetWindowDisplayAffinity(hwnd, WDA_MONITOR);

From Old New thing

That said, the customer could modify their proprietary program to call the Set­Window­Display­Affinity function to indicate that the window contents should not be included in screen captures, as I noted some time ago. The desktop compositor will prevent those pixels from being included in Bit­Blt and other screen capture functions.

UWP applications can set the Application­View.Is­Screen­Capture­Enabled property to false to exclude a view from screen capture functions.

That said, this only makes it slightly more difficult to capture data. There are ways around it, and whatever you do, you cannot prevent anyone from whipping out a mobile phone and taking a picture, or just writing down the important parts to a notepad.

Upvotes: 1

Related Questions