Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I ensure a form displays on the "additional" monitor in a dual monitor scenario? [duplicate]

I have an application in which there is a form which I want to show on second screen.

Mean If application is running on screen A and when I click on menu to show Form it should display on Screen B and same with if application is running on screen B and when I click on menu to show Form it should display on Screen A.

like image 653
Mohsan Avatar asked Apr 01 '10 14:04

Mohsan


People also ask

How do I configure dual monitor settings?

To get the best possible match between your monitors, calibrate them to the same color temperature, brightness and gamma settings if possible. Use the monitor with the lowest brightness as your common denominator for all the other monitors.


2 Answers

You need to use the Screen class to find a screen that the original form is not on, then set the second form's Location property based on that screen's Bounds.

For example:

var myScreen = Screen.FromControl(originalForm); var otherScreen = Screen.AllScreens.FirstOrDefault(s => !s.Equals(myScreen))                 ?? myScreen; otherForm.Left = otherScreen.WorkingArea.Left + 120; otherForm.Top = otherScreen.WorkingArea.Top + 120; 

This will work for any number of screens.

Note that it is possible that the video card is configured so that Windows sees one large screen instead of two smaller ones, in which case this becomes much more difficult.

like image 95
SLaks Avatar answered Oct 11 '22 12:10

SLaks


Below is a function allowing you to display a form on any monitor. For your current scenario you can call this showOnMonitor(1);.

Essentially you have to get screen information from Screen.AllScreens and then get the dimensions of each, then place your form where you need it

function void showOnMonitor(int showOnMonitor) 
{ 
    Screen[] sc; 
    sc = Screen.AllScreens; 

    Form2 f = new Form2(); 

    f.FormBorderStyle = FormBorderStyle.None; 
    f.Left = sc[showOnMonitor].Bounds.Left; 
    f.Top = sc[showOnMonitor].Bounds.Top; 
    f.StartPosition = FormStartPosition.Manual; 

    f.Show(); 
}

Note don't forget to do validation to ensure you actually have two screens etc else an exception will be thrown for accessing sc[showOnMonitor]

like image 20
Chris Avatar answered Oct 11 '22 12:10

Chris