Disable screen capture in windows forms desktop applications using c#
Loading
Disable screen capture in windows forms desktop applications using c#
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Jaish MathewsPosted Jan 7, 2025, 12:37 PM
To disable screen capture in a Windows Forms desktop application using C#, you can employ techniques such as using window attributes or direct APIs that restrict screen capture.
Below are approaches you can use:
1. Use the
SetWindowDisplayAffinityAPI (Windows 8 and later)The
SetWindowDisplayAffinityfunction prevents screen capture by marking the window as non-screen-capturable. This works for tools like Snipping Tool or Print Screen, but it may not stop all third-party screen recording tools.Implementation
2. Black Out Sensitive Content on Minimized
Instead of preventing screen capture, you can obscure sensitive content when the application is minimized or not in focus.
Implementation
3. Block Screen Capture via Registry (Group Policy)
While not a code-level solution, you can modify Windows Group Policies or registry keys to restrict screen capture for specific applications. This requires admin privileges and might not be app-specific.
Limitations
SetWindowDisplayAffinityonly works on systems with DWM (Desktop Window Manager) enabled and might not block all screen capture tools.Best Practices