Search code examples
c#.netwpfwinformsinterop

How can I tell when a screen's WorkingArea changes (i.e. task bar is moved)?


I have some windows docked to edges/corners of the working area, and I need to know if/when the WorkingArea of the screen changes so I can update the position of those windows. I've attempted to tackle this before to no avail, as I recall.


Solution

  • One way would be to register your windows as an Application Desktop Toolbar (AppBar) http://msdn.microsoft.com/en-us/library/bb776821(VS.85).aspx Then the system will send you notifications when your window needs to be repositioned, resized etc. For example an AppBar receives a ABN_POSCHANGED notification from the system when something occurs that will affect the size/position/visiblity etc. of the AppBar.

    You will need to interop to do this, here is a Code Project article on doing this with C#, though I have only done with C++ so I cannot vouch for the article, but it should be a fair starting point. http://www.codeproject.com/KB/dotnet/AppBar.aspx