D
D
Dmitry Korolev2019-04-08 05:04:19
Windows
Dmitry Korolev, 2019-04-08 05:04:19

How to find out the number of the desktop on which the window?

How to find out from the win forms window on which desktop by number it is located in Windows?
Is there an event that the window has moved to another desktop?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey Pavlov, 2019-04-08
@lexxpavlov

If you need exactly the monitor number, and not the desktop, then you need the System.Windows.Forms.Screen class, which has a lot of useful things. For example, Screen.FromControl(), Screen.FromHandle()etc. Or you can use the AllScreens property, which stores all monitors in the system.
There is a nuance here - FromHandle does not take the top left point of the window, but the middle of the top border of the window. See what you need.
And one more nuance - the monitor numbers in the AllScreens list may not match the monitor number in the Windows screen settings. I could not find this Windows monitor number. Windows numbers depend on the video card port to which they are connected.

J
John_Nash, 2019-04-08
@John_Nash

As I understand it, we are talking about multiple monitors, not multiple desktops. If the first, then you need to dig from the EnumDisplayMonitors function

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question