6

I actually work on two little wpf application for track, one is on the principal computer, you can wrote the time of the pilot on, the second must display in a big screen connect to the principal computer in hdmi and just display the time to the pilot.

I have ever made everything and all work fine.

But when I launch the first application, I want the second application automaticaly launch in the second screen. I only find a solution with the Forms packages like :

System.Windows.Forms.Screen.AllScreens

But I work with WPF so I can't access to System.Windows.Forms.

Anyone as an idea of possible solution? Thanks a lot!

nicar
  • 157
  • 1
  • 14
  • 1
    `this.Location = Screen.AllScreens[1].WorkingArea.Location;` have you tried using this? 1 being the second monitor and 0 the first. – Tim van Gool Mar 09 '15 at 14:36

1 Answers1

4

Even though it is a WPF app you can still reference System.Windows.Forms. Simply right click on the project in solution explorer, add references, and select System.Windows.Forms.

Then use something like this: (you will also need a reference to System.Drawing)

public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
        this.MaximizeToSecondaryMonitor();
    }

    public void MaximizeToSecondaryMonitor()
    {
        var secondaryScreen = Screen.AllScreens.Where(s => !s.Primary).FirstOrDefault();

        if (secondaryScreen != null)
        {
            var workingArea = secondaryScreen.WorkingArea;
            this.Left = workingArea.Left;
            this.Top = workingArea.Top;
            this.Width = workingArea.Width;
            this.Height = workingArea.Height;

            if (this.IsLoaded)
            {
                this.WindowState = WindowState.Maximized;
            }
        }
    }
}

code taken from here

Community
  • 1
  • 1
Toby Crawford
  • 787
  • 5
  • 6