Reputation: 8172
My application pops up a custom dialog whenever new items are found in an RSS feed, the custom dialog starts off the bottom of the screen, raises up, pauses, and then drops back down.
I want the dialog to be on top of other windows (because the notices are important to me), so I set the TopMost property on the form to true. Problem is it is also on top of the task bar (which I don't want).
Is there a way to make the dialog be on top of other windows, but not the task bar?
(Please don't discuss whether or not I should do this. This is a custom application for my use only, and that is the way I want it to work. I have also added a setting to turn this functionality on/off, in case I don't want it to work like that anymore.)
Upvotes: 2
Views: 3454
Reputation: 6343
There's a good example of a popup above the taskbar here:
http://www.codeproject.com/KB/miscctrl/taskbarnotifier.aspx
If the user is dragging the window, you'll need to override the OnPaint
event. The key is calling SetBounds()
on the form, calculating the bounds from the form size and Screen.PrimaryScreen.WorkingArea
, which excludes the taskbar from its height.
HTH,
James
Upvotes: 1
Reputation: 29632
The reason this is not going to work is because you don't know whether the top most window you want the popup to be over is going to be above or below the taskbar. Most of the time, an actual top most window will lie over the taskbar. You can't have a window underneath the taskbar and above the other window if the other window is already over the taskbar.
You can fiddle a little bit with SetWindowPos and see whether you maybe get a result you like, but this will get very difficult.
See http://msdn.microsoft.com/en-us/library/ms633545(VS.85).aspx for how SetWindowPos() works and http://www.pinvoke.net/default.aspx/user32.setwindowpos and http://www.pinvoke.net/default.aspx/Constants.SWP for how you can call this function from WinForms.
Upvotes: 1