0

I come here because I have to, on a project, block access to windows users to applications.

I have a client/server architecture, with a client listening on a port. When the server sends a message, the client must open a WPF window, with the message sent by the server. (message such as "Fire Alert","Terrorist Attack" or other). So, my WPF has to make more than sixty percent of the screen, be in the foreground.

For the moment, I've put my form in TopMode, with a size that makes sixty percent of the screen.

this.Height = (System.Windows.SystemParameters.PrimaryScreenHeight * 0.60);
this.Width = (System.Windows.SystemParameters.PrimaryScreenWidth * 0.60);
WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen;
this.Topmost = true;

The problem is when there is a split screen (or more than two screens), I can't block the second screen. So I thought about disabling the second screen, but I didn't find much on the internet.

So I'm here to ask for advice, do you know if that's possible? Do you have any other ideas?

Thank you !

Y.op
  • 79
  • 1
  • 1
  • 9
  • I forgot to change it in code world ^^' – Y.op Nov 07 '17 at 13:49
  • You could [use this](https://stackoverflow.com/questions/3750113/launch-an-application-and-send-it-to-second-monitor) but to force it to monitor 1 – BugFinder Nov 07 '17 at 13:49
  • Why do you want to stop access to applications? – PaulF Nov 07 '17 at 13:51
  • Making your form cover parts of the screen does not prevent access to anything as the user can just kill your application. Consider another approach. – Equalsk Nov 07 '17 at 13:52
  • @m.rogalski after question update, your comment seems kind of confusing :) – SᴇM Nov 07 '17 at 13:52
  • @SeM-ՍեՄ Ah, yes. I haven't seen that it was updated. – mrogal.ski Nov 07 '17 at 13:53
  • 3
    AFAIK there is a special mode for this in windows. In German it's called "Kiosk Mode" ... – Fildor Nov 07 '17 at 13:53
  • 3
    @Fildor Kiosk mode in English too – DavidG Nov 07 '17 at 13:54
  • 1
    See https://learn.microsoft.com/en-us/windows/configuration/kiosk-shared-pc – Fildor Nov 07 '17 at 13:55
  • 1
    @DavidG Yes, I just saw it. Sounded a bit too "German" for me to consider it to be the common name for the functionality. :D – Fildor Nov 07 '17 at 13:56
  • Most of the workstations are on windows 7 :/ – Y.op Nov 07 '17 at 13:58
  • There you go: https://blogs.technet.microsoft.com/keithmayer/2012/08/03/building-public-kiosk-workstations-with-windows-7-and-windows8-itpro/ – Fildor Nov 07 '17 at 14:00
  • @Equalsk The objective is not to block the user, but really to display a message, disabling the second screen, to show clearly that it is necessary to stop working. – Y.op Nov 07 '17 at 14:01
  • _"to display a message, disabling the second screen, to show clearly that it is necessary to stop working"_ - Oh, then Kiosk is not for you anyway. Can you give a little more context? – Fildor Nov 07 '17 at 14:01
  • So you want to display a large message on each screen? You can use the [Screen.AllScreens Property](https://msdn.microsoft.com/en-us/library/system.windows.forms.screen.allscreens(v=vs.110).aspx) as a starting point, once you have this information the rest should be straightforward. – Equalsk Nov 07 '17 at 14:06
  • I have a client/server architecture, with a client listening on a port. When the server sends a message, the client must open a WPF window, with the message sent by the server. (message such as "Fire Alert","Terrorist Attack" or other). So, my WPF has to make more than sixty percent of the screen, be in the foreground. That's why I'm worried about the second screen. – Y.op Nov 07 '17 at 14:07
  • 1
    This is all information that should have been in your question along with a tag for `WPF`. This is why you have so many comments guessing at what you want rather than an answer. Hint: Edit this new information into your question. – Equalsk Nov 07 '17 at 14:17
  • When I count the number of screens with the Allscreens function and Length, I only have one screen, it does not detect my second screen :/ – Y.op Nov 07 '17 at 14:32
  • @Y.op why not simply open 1 window per screen you detect so you make sure it's displayed everywhere no matter the user setup. – Franck Nov 07 '17 at 15:47
  • This is what I'm trying to do, but I can't find much to open the form on all screens. – Y.op Nov 08 '17 at 06:58
  • How are your screens set up? And how are your monitors connected to your machine? Can you reproduce the behavior on other machines? Are there machines, where `AllScreens` works as expected? – Fildor Nov 08 '17 at 07:59
  • Allscreen detects well my second screen, now I have to find out how to open my application on the different screens. – Y.op Nov 08 '17 at 08:04

1 Answers1

0

If you want to block access outside the form you need to make your form modal.

Here is how to do it:

Form f = new Form();
 f.TopMost = true;
 f.ShowDialog()

Or if you want to use your current form:

 private void Form1_Load(object sender, EventArgs e)
 {            
     this.TopMost = true;          
     this.ShowDialog();
 }
Alexey Subach
  • 11,903
  • 7
  • 34
  • 60
S Nash
  • 2,363
  • 3
  • 34
  • 64
  • Yes, That's what I do with this.TopMost, but the problem is the second screen, the application only opens on one screen – Y.op Nov 07 '17 at 14:10