question

DeepakHirapur-5185 avatar image
0 Votes"
DeepakHirapur-5185 asked ·

WPF application in Dual monitor environment, application is not launching in proper screen.

Hi all,

Our requirement is as below.
In dual monitors(screens) use case, our WPF application should launch in the monitor (screen) where the application was closed at the previous time.

Steps to execute the issue:
1) Launch WPF application in Screen 1 with maximize state.
2) Resize the application in Screen 1.
3) Maximize and Close the application in Screen 1.
4) Launch WPF application.

[Actual Result]
WPF application is launched in Screen 2.

[Expected Result]
WPF application is launched in Screen 1.
WPF application should be launched in the screen where it was closed at the previous time.

Note:
However, if WPF application is executed in Screen 2 with the above same steps, WPF application is launched in Screen 2.

Other standard applications i.e. Explorer, MS Paint etc.., behavior is same as our requirement.

We have tried below following approaches.
1) Updating Window Left and Top properties in the MainWindow constructor, Which is retrieved from Config Xml file.
this.Left = Config.Left;
this.Top = Config.Right;

2) Retrieving Window Left & Top value from GetMousePosition () API method and updating in Window Loaded event method.
DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
internal static extern bool GetCursorPos(ref Win32Point pt);

     [StructLayout(LayoutKind.Sequential)]
     internal struct Win32Point
     {
         public Int32 X;
         public Int32 Y;
     };

     public static Point GetMousePosition()
     {
         var w32Mouse = new Win32Point();
         GetCursorPos(ref w32Mouse);

         return new Point(w32Mouse.X, w32Mouse.Y);
     }

3) Retrieving Screen Bounds based on screen value & Updating Window Left and Top properties. Screen value is stored in Config xml file.
0=> Primary Screen, 1=>Secondary Screen.
System.Drawing.Rectangle screenBounds = System.Windows.Forms.Screen.AllScreens[].Bounds;
this.Left = screenBounds.Left;
this.Top = screenBounds.Top;


Please help us to resolve the issue to meet our requirement.



windows-wpfdotnet-wpf-xaml
· 4
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.


How do you “launch WPF application in Screen 2”?

0 Votes 0 ·

We will launch from Taskbar or search menu.

0 Votes 0 ·
Viorel-1 avatar image Viorel-1 DeepakHirapur-5185 ·

If you try another, simplest WPF application, which does not have any Config and code, does it work as expected?

0 Votes 0 ·
Show more comments

0 Answers