Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I know what monitor a WPF window is in

Tags:

c#

.net

wpf

In a C# application, how can I find out if a WPF window is in the primary monitor or another monitor?

like image 699
tom greene Avatar asked Mar 17 '10 20:03

tom greene


People also ask

How do I display a WPF window?

When a Window is created at run-time using the Window object, it is not visible by default. To make it visible, we can use Show or ShowDialog method. Show method of Window class is responsible for displaying a window.

How do I know if a WPF window is open?

In WPF there is a collection of the open Windows in the Application class, you could make a helper method to check if the window is open. Here is an example that will check if any Window of a certain Type or if a Window with a certain name is open, or both. Show activity on this post. Show activity on this post.

How do I open a WPF window in full screen?

Just set the WindowState to Maximized , and the WindowStyle to None . Also setting the Window as topmost will make sure no other Window shows up over your window.


1 Answers

If the window is maximized then you cannot rely on window.Left or window.Top at all since they may be the coordinates before it was maximized. But you can do this in all cases:

    var screen = System.Windows.Forms.Screen.FromHandle(        new System.Windows.Interop.WindowInteropHelper(window).Handle); 
like image 194
Mike Blandford Avatar answered Oct 05 '22 23:10

Mike Blandford