0

I have a win form that pops up after a certain action is performed. I would like this, which is centered on the screen, to lock access to any other window until the form is closed.

Basically stay on top and not be able to access other forms. How can I do this?

NotMe
  • 87,343
  • 27
  • 171
  • 245
user541597
  • 4,247
  • 11
  • 59
  • 87
  • 8
    Block access to other forms in your application, or system-wide? You can't stop `ctrl+alt+del` + kill process.. – Blorgbeard Apr 03 '13 at 23:36
  • system-wide, aside from ctrl+alt+del – user541597 Apr 03 '13 at 23:38
  • 1
    http://stackoverflow.com/questions/3999998/how-to-make-a-system-modal-dialog-in-c – Lee Taylor Apr 03 '13 at 23:41
  • If you're trying to achieve the UAC effect, this is a very hard task, unless you create a new Desktop and place the modal form on it. Modal dialog will work only on current application, but other windows from other applications will be accessible. – Stas Apr 03 '13 at 23:53
  • What's the point of this? Are you really warning the user of a critical security vulnerability? This does not make sense in any other case. – Cody Gray - on strike Apr 04 '13 at 02:32

2 Answers2

1

What you're looking for is a modal form : Displaying Modal and Modeless Windows Forms

Form1 form1 = new Form1();
/* Calling ShowDialog instead of Form.Show() will force
* the user to close that form first */
form1.ShowDialog();

Update 1 :

If you are looking for a system-wide blocking just as Workrave software does, one could do the following :

  • Create a window with no borders, maximized and make the borders (in your case very large ones) transparent. In the middle of this window there would be your pseudo dialog-box.

  • Similarly, one would take a screenshot and display it in that form, but you wouldn't see screen activity should there be some.

Example of Workrave blocking activity :

enter image description here

You cannot do anything on your desktop unless you skip/postpone that rest break.

Note : Workrave is a program that assists in the recovery and prevention of Repetitive Strain Injury (RSI). The program frequently alerts you to take micro-pauses, rest breaks and restricts you to your daily limit. (from their website)

Update 2 : As Wrokrave is open-source, one could just browse through the code to see how they did implement that blocking system : http://sourceforge.net/projects/workrave/

aybe
  • 15,516
  • 9
  • 57
  • 105
  • that is what I am using but I need it to be system wide. – user541597 Apr 03 '13 at 23:38
  • 2
    What about, like, Alt+Tab? – Cody Gray - on strike Apr 04 '13 at 02:30
  • But it should prevent all the keyboard shortcuts...for example( Win+D) to minimize all the active forms & Windows. – reaz Apr 04 '13 at 02:38
  • One could easily trap those key combinations : http://stackoverflow.com/questions/1346689/how-do-i-trap-windows-key-alttab-ctrlaltdelete-in-c – aybe Apr 04 '13 at 12:54
  • Not "easily". Writing your own GINA DLL is a *huge* undertaking, and works only in versions of Windows prior of Vista. That all changed with Vista; those answers are obsolete. – Cody Gray - on strike Apr 04 '13 at 16:25
  • There are certainly some ways to do so, when taking an exam at Prometric centers, you cannot do anything else than what they want you to do : pass your exam. Not sure how it's done whether through Group Policy or not but it is possible. But for Ctrl-Alt-Del there's certainly more involved... – aybe Apr 04 '13 at 18:35
0

Can you use:

YourForm.ShowDialog().

ShowDialog does not allow the background forms to be accessed unless the current form is closed.

Vaibhav Desai
  • 2,618
  • 1
  • 16
  • 16