T.B Ygg
T.B Ygg

Reputation: 116

How to open process on dual monitor?

i have a C# application that should open a process on the second screen if there are more than one screen. I just cannot get it working. Any ideas?

Array screens = Screen.AllScreens;
if (screens.Length > 1)
{
    // open in the second monitor
}
else
{
    System.Diagnostics.Process.Start(InputData);
}

It should be the same data as in else, but just open this on the second monitor in the now empty if.

Upvotes: 0

Views: 1529

Answers (3)

BRAHIM Kamel
BRAHIM Kamel

Reputation: 13794

you can achieve this by changing your MainForm of the input process like the following

public Form1()
        {
            this.StartPosition =FormStartPosition.Manual;
            InitializeComponent();

            Screen sndSc = Screen.AllScreens[1];

            if (sndSc.Primary)
            {
                sndSc = Screen.AllScreens[0];            
            }
            this.Height = sndSc.WorkingArea.Height;
            this.Width = sndSc.WorkingArea.Width; 
            this.Location = sndSc.WorkingArea.Location;   
        }

Upvotes: 2

Thomas Levesque
Thomas Levesque

Reputation: 292705

There is no standard way to specify on which screen the application will appear when you launch it. However, you could either:

  • handle that in the started app itself (if you have its code of course)
  • find the handle of the main window after the process has started, and move it to the second screen using Win32 interop

Upvotes: 3

AgentFire
AgentFire

Reputation: 9800

You should do the same thing you do when you position your window.

To display a window on any monitor, you should reposition it according to that monitor's coordinates.

Lets say you have two monitors, both of 1920x1080 resultion and they are arranged side by side. In this situation, to show a form on the second screen, you must set form's X coordinate (or Left property, my guess) more than 1920.

Upvotes: 1

Related Questions