Click here to Skip to main content
15,867,568 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a wpf app wich load multiple windows in two screens at same time (when the app is executed). Windows can be small or full screen but all of them have a location in the screen specified for them (screenIndex) in screen points (x,y). My problem is they process correctly the X,Y location on a screen but they are displayed on the same screen ( no matter what screen I specify). I tried next code options and I don't see what can be the problem . Also I could not found another succesfully solution:

One option:

C#
  private void ShowByCoordinates(Window window, int screenId, int LeftTransform, int TopTransform){
window.WindowStartupLocation = System.Windows.WindowStartupLocation.Manual;
System.Drawing.Rectangle totalSize = System.Drawing.Rectangle.Empty;
System.Windows.Forms.Screen s0 = System.Windows.Forms.Screen.AllScreens[screenIndex];
                totalSize = System.Drawing.Rectangle.Union(totalSize, s0.Bounds);   


           window.Width = totalSize.Width;
           window.Height = totalSize.Height;

            window.Left = LeftTransform;
            window.Top = TopTransform;
            window.Show();
}

Option 2:
C#
System.Windows.Forms.Screen s0 = System.Windows.Forms.Screen.AllScreens[screenId];// My screenId (int) specified
           Rectangle r0 = s0.WorkingArea;
           r0.X = TopTransform;// My int coordinate
           r0.Y = LeftTransform;// My int coordinate
           window.Topmost = true;
           window.Top = r0.X;
           window.Left = r0.Y;
           window.Show();
Posted
Updated 14-Jul-15 1:46am
v4

1 solution

Solution applied:

C#
private void ShowByCoordinates(Window window, int screenId, int LeftTransform, int TopTransform){
System.Drawing.Rectangle bounds = System.Drawing.Rectangle.Empty;
            System.Windows.Forms.Screen s0 = System.Windows.Forms.Screen.AllScreens[screenId];
            bounds = s0.WorkingArea;
            window.Left = bounds.X + LeftTransform;
            window.Top = bounds.Y + TopTransform;
            window.Show();
}


It was pretty simple but I was conviced to set the working area or stuff like that.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900