How to create form popup from from system tray on windows application (not web) with c#
I have a winform application in c#. the main form is usually minimized. When some event occur, i want to create small popup form that animate above the tray icon with message, click on it, will bring up the main form.
To impl开发者_Go百科ement that, i just create simple form ? or there is special system form for that ? for example, there is the popup message that alert on new mail with msn messenger.
Thanking in advance.
Here's a SO question that covers that very topic. What you're looking for is called a "toast" message.
The "Toast" popup that msn uses is a custom one, but there is a built in ShowBalloonTip method on notifyicon
see http://msdn.microsoft.com/en-us/library/system.windows.forms.notifyicon.aspx
You can just create a (borderless) form to do this. You might also want to have a loot at the excellent Transitions library for fading in/out, sliding around or resizing smoothly.
I've had success using the NotifyIcon control in WinForms. Add a NotifyIcon in your form, then call its ShowBalloonToolTip function in your event handler to display your message. Define an event handler for the NotifyIcon.DoubleClick event, and popup your main window. Be sure to also hide the balloon message as well.
A decent example of how to do this can be found here.
The same technique is recommended in WPF, though I'm not a fan about including WinForms components in a WPF app. I've done it before, but it hurts the soul.
form.showdialog()
should work where form is an instance of a form class.
For some code, you can refer to WorkingWithWinForms.
If you want to display a question or an info, you can use MessageBox
. here is a messagebox-show.
You should create a normal form.
If you don't want normal window chrome (titlebar & frame), set FormBorderStyle
to None
.
精彩评论