I'm using a Form to show notifications (it appears at the bottom right of the screen), but when I show this form it steals the focus from the main Form. Is there a way to show this "notification" form without stealing focus?
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Generic Generics in Managed C++
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
Hmmm, isn't simply overriding Form.ShowWithoutActivation enough?
And if you don't want the user to click this notification window either, you can override CreateParams:
I know it may sound stupid, but this worked:
You can handle it by logic alone too, although I have to admit that the suggestions above where you end up with a BringToFront method without actually stealing focus is the most elegant one.
Anyhow, I ran into this and solved it by using a DateTime property to not allow further BringToFront calls if calls were made already recently.
Assume a core class, 'Core', which handles for example three forms, 'Form1, 2, and 3'. Each form needs a DateTime property and an Activate event that call Core to bring windows to front:
And then create the work in the Core Class:
On a side note, if you want to restore a minimized window to its original state (not maximized), use:
Again, I know this is just a patch solution in the lack of a BringToFrontWithoutFocus. It is meant as a suggestion if you want to avoid the DLL file.
Figured it out:
window.WindowState = WindowState.Minimized;
.Create and start the notification Form in a separate thread and reset the focus back to your main form after the Form opens. Have the notification Form provide an OnFormOpened event that is fired from the
Form.Shown
event. Something like this:You can also keep a handle to your NotifcationForm object around so that it can be programmatically closed by the main Form (
frm.Close()
).Some details are missing, but hopefully this will get you going in the right direction.