Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
497 views
in Technique[技术] by (71.8m points)

c# - How do I know what monitor a WPF window is in

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...