How to lock screen using C #?

I am just writing my first C # application, which is a scheduler. Once an hour, I want to pop up a dialog box and lock the screen for two minutes to take a break.

At the moment, my application simply shows the form in "TopMost" when its time is torn and hidden after two minutes.

How can I lock the screen? Something similar to the UAC style in Vista.

+5
source share
2 answers

As an alternative to taking screen capture (which I also used as an approach in the past under slightly different circumstances), you can also do this by creating a new window (WinForm) that is full-screen and on top of all other windows.

If you set the background color of the background to black, set the opacity to 70-80%, you get what looks like a UAC prompt in Vista.

eg.

formName.WindowState = FormWindowState.Maximized; 
formName.FormBorderStyle = FormBorderStyle.None; 
formName.Opacity = 0.70; 
formName.TopMost = true;

Of course, it would be wise to draw a window on top of this, informing the user about why the screen was darkened using a counter.

As with the shielding approach, this on its own does not prevent the user by passing it using the Windows key Alt- Tabor Ctrl- Escto open the Start menu, or to switch to other tasks. This is a little trickier.

+5

Eep, . UAC Vista . CreateDesktop. SwitchDesktop, .

, , .


, :

LockWorkStation.

​​ . , . , , , , .

+8

All Articles