Answer Dual Screen Application and WPF

  • Friday, November 09, 2007 4:01 PM
     
     
    Hello,
    I want to make a dual sreen application and I search functions to execute a part or a full application in the second screen.
    I found a article but it's about Windows Form Application ( frm.StartPosition...).
    How can I use the seconde monitor ? Is-it possible in WPF ?

    Thanks
    Fabrice Debonlier

Answers

  • Friday, November 09, 2007 6:08 PM
    Moderator
     
     Answer

    Actually, the method outlined in that article will work in WPF as well as Windows Forms with a few minor tweaks for the WPF version. Here is what I did and this is just one way to accomplish the effect.

    1. Started a new WPF Application project in Visual Studio
    2. Added the needed references to System.Windows.Forms (needed for Screen) and System.Drawing (needed for Rectangle)
    3. Removed the StartupUri in the App.xaml file and overrode the OnStartup() method in code-behind. I did this because StartupUri points to just one Window, Window1.xaml, in the WPF Application template and OnStartup will let me control what happens when the application starts.
    4. Added Window2.xaml to the project so that I would have a second Window to display on a second monitor.
    5. Added code similar to the article you linked to the override of OnStartup  which was:
    Code Block

            protected override void OnStartup(StartupEventArgs e)
            {
                base.OnStartup(e);

                Window1 w1 = new Window1();
                Window2 w2 = new Window2();


                Screen s1 = Screen.AllScreens[0];
                Screen s2 = Screen.AllScreens[1];

                Rectangle r1 = s1.WorkingArea;
                Rectangle r2 = s2.WorkingArea;

                w1.Top = r1.Top;
                w1.Left = r1.Left;

                w2.Top = r2.Top;
                w2.Left = r2.Left;

                w1.Show();
                w2.Show();

                w2.Owner = w1;


            }

     

    Keep in mind that this is just a quick example and you should always have checks for whether or not you are running on single monitor machines and you may want one of the Windows to own the other so that you can close the owner to stop the application.

     

    Hope this helps,

    Larry Olson

    WPF Program Manager

All Replies

  • Friday, November 09, 2007 6:08 PM
    Moderator
     
     Answer

    Actually, the method outlined in that article will work in WPF as well as Windows Forms with a few minor tweaks for the WPF version. Here is what I did and this is just one way to accomplish the effect.

    1. Started a new WPF Application project in Visual Studio
    2. Added the needed references to System.Windows.Forms (needed for Screen) and System.Drawing (needed for Rectangle)
    3. Removed the StartupUri in the App.xaml file and overrode the OnStartup() method in code-behind. I did this because StartupUri points to just one Window, Window1.xaml, in the WPF Application template and OnStartup will let me control what happens when the application starts.
    4. Added Window2.xaml to the project so that I would have a second Window to display on a second monitor.
    5. Added code similar to the article you linked to the override of OnStartup  which was:
    Code Block

            protected override void OnStartup(StartupEventArgs e)
            {
                base.OnStartup(e);

                Window1 w1 = new Window1();
                Window2 w2 = new Window2();


                Screen s1 = Screen.AllScreens[0];
                Screen s2 = Screen.AllScreens[1];

                Rectangle r1 = s1.WorkingArea;
                Rectangle r2 = s2.WorkingArea;

                w1.Top = r1.Top;
                w1.Left = r1.Left;

                w2.Top = r2.Top;
                w2.Left = r2.Left;

                w1.Show();
                w2.Show();

                w2.Owner = w1;


            }

     

    Keep in mind that this is just a quick example and you should always have checks for whether or not you are running on single monitor machines and you may want one of the Windows to own the other so that you can close the owner to stop the application.

     

    Hope this helps,

    Larry Olson

    WPF Program Manager

  • Monday, November 12, 2007 8:37 AM
     
     
    Thanks !

    It works.

    I was looking for :


    Window1 w1 = new Window1();

    w1.StartPosition = WindowsStartPosition.Manual;


    I have not been able to find alone.

  • Monday, November 12, 2007 9:31 PM
     
     
    You mean the Window.WindowStartupLocation property? The default value is WindowStartupLocation.Manual, so there is no need to set it.