0

I have written a program (C#) which loads a form. On the primary screen it displays different text when I click OK. But the problem is... I am working with dual monitor, so when I load a form on the primary screen and drag it to secondary screen and click OK, it automatically moves back to the primary screen.

I have written a method which determines which screen the form is currently loaded on, which is working fine. However, when I tried to relocate it to the secondary screen, it no longer works (it's still moving back to the primary screen). I'm not sure what I'm doing wrong.

Here is my code:

if(Currentscreen == "primary")
{
    forma.showDialog(this);//this is ok showing form on main screen
}
else
{
    int showOnMonitor = 1;
    Screen[] scr;
    scr = Screen.AllScreens;
    forma.StartPosition = FormStartPosition.CenterParent;
    forma.Location = new Point(sc[showOnMonitor].Bounds.Left, sc[showOnMonitor].Bounds.Top);  //this line should relocate it on secondary screen
    forma.showDialog(this);  //but its again loading on Primary monitor
}
Rohit Vipin Mathews
  • 11,629
  • 15
  • 57
  • 112
DeveloperSD
  • 129
  • 1
  • 2
  • 8
  • if(Currentscreen ="primary") { forma.showDialog(this);//this is ok showing form on mainscreen } else { int showOnMonitor = 1; Screen[] scr; scr = Screen.AllScreens; forma.StartPosition = FormStartPosition.CenterParent; forma.Location = new Point(sc[showOnMonitor].Bounds.Left, sc[showOnMonitor].Bounds.Top);//this line should relocate it on secondary screen forma.showDialog(this);//but its again loading on Primary monitor } – DeveloperSD Jul 14 '15 at 12:51
  • please add relevant tags like which project you are working on, framework, etc. – Rohit Vipin Mathews Jul 14 '15 at 12:57
  • .Net 4.0, visual studio 2012, c# – DeveloperSD Jul 14 '15 at 13:07
  • I guess the project is Win Forms? – Rohit Vipin Mathews Jul 14 '15 at 13:10
  • yup got any solution Rohit?? – DeveloperSD Jul 14 '15 at 13:20
  • its not working as well – DeveloperSD Jul 14 '15 at 13:25
  • what didn't work? There are two suggestions in that post, setting the `StartPosition` to manual, and setting the location using `Screen.AllScreens[1].WorkingArea.Location;`. Did you try both of these and neither worked? – DrewJordan Jul 14 '15 at 13:52
  • yes i tried both but every time fome come back to Promaryscreen. – DeveloperSD Jul 14 '15 at 13:57
  • try this: 1. make property - StartPosition to Manual 2. forma.Location = Screen.AllScreens[numOfScreen].WorkingArea.Location; // numOfScreen=1 – snir Sep 04 '17 at 14:35

0 Answers0