Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
The notify icon article started out because I realized, even internally that the best practice for this wasn't very obvious. I thought I'd share the "other" solutions to the problem, and their pitfalls. ;-)
Approach 1: Start off with Form.Opacity = 0, then when ready to show, change Form.Opacity = 1
Pitfall: Form resize may be significantly slower, as playing with the opacity property can turn off hardware acceleration.
Approach 2: Start with ShowInTaskbar = false, WindowState = FormWindowState.Minimized, when ready to show toggle both these properties.
Pitfall: Ugly flicker of the form, as toggling the ShowInTaskbar property after the handle has been created actually destroys the form and recreates it in place (calls RecreateHandle).
Approach 3: Change StartPosition to FormStartPosition.Manual, place it offscreen.
Pitfall: This approach is the most reasonable of the three; it is just very easy to get this one incorrect by not taking into account multiple monitors, scaling, etc.
How do you actually do this? Use ApplicationContext.
Comments
- Anonymous
September 18, 2005
Hello, thanks for nice articles. Could you please write one about creating combobox-style controls using WinForms? I mean control with a popup element, which is hidden when user clicks (or tabs, alt-tabs, win-button, hit global shortcut which activates something)somewhere outside it, like combo drop-down, popup menu and such. I've spent a lot of time trying to mimic this behavior including various WinAPI calls, hooks, modal loops, etc, but can't get it work just right.