Search code examples
.netwpfmultiple-monitors

How to open a WPF Application in a specific Place on a Specific Monitor


I have two application which communicates together, to be more specific I have app1.exe and app2.exe this 2 apps are in the same PC which has one monitor and one TV how can I open app1.exe on TV and the other on my Monitor. Actually to do this I'm using a third party tool which is named Actual Multiple Monitors. my goal is to remove this tool because I'm using this only for the function to open my applications in the right place. it would be great if there is a possibility to do this using code. I'm using WPF in Visual Studio 2010?


Solution

  • The following assumes that you have the source code to your applications:

    You need to do a couple of things:

    Firstly use System.Windows.Forms.Screen() to enumerate your screens.

    Screen[] allScreens = Screen.AllScreens;

    Then you can you use the Screen.Bounds property to determine where to display your main window.

    I don't know how you change the location of your main window in WPF - in Windows Forms you just override OnLoad() and set the Form.Location and Form.Size appropriately. I imagine WPF has something similar.