c# winform 類似android toast消息功能


先看下效果:

支持動畫,支持聲音,支持定時自動關閉

使用方法:

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
        );

  

源碼下載

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM