先看下效果:
支持動畫,支持聲音,支持定時自動關閉
使用方法:
var notifycation = new Notification(“My Notification”, "My notification message goes here", 2, "Slide", "Right");
notifycation.show();
用起來就這么簡單,第一個參數是title,第二個是內容,背景紅色是可以換的,第三個參數是自動關閉時間,第四個是窗口動作,淡入淡出,或者滑翔,第五個參數是從左邊還是右邊,上邊還是下邊出來
支持多個toast,消失之前會疊加不會蓋住,
核心源碼:
if (duration < 0) duration = int.MaxValue; else duration = duration * 1000; lifeTimer.Interval = duration; labelTitle.Text = title; labelBody.Text = body; _animator = new FormAnimator(this, animation, direction, 500); Region = Region.FromHrgn(NativeMethods.CreateRoundRectRgn(0, 0, Width - 5, Height - 5, 20, 20));
[DllImport("user32")] internal extern static bool AnimateWindow(IntPtr hWnd, int dwTime, int dwFlags); [DllImport("Gdi32.dll", EntryPoint = "CreateRoundRectRgn")] internal static extern IntPtr CreateRoundRectRgn ( int nLeftRect, // x-coordinate of upper-left corner int nTopRect, // y-coordinate of upper-left corner int nRightRect, // x-coordinate of lower-right corner int nBottomRect, // y-coordinate of lower-right corner int nWidthEllipse, // width of ellipse int nHeightEllipse // height of ellipse );