C#實現右下角彈窗

來源:互聯網
上載者:User

標籤:

http://wenku.baidu.com/view/c1ad1227482fb4daa58d4bfe.html  /// <summary>    /// 枚舉,描述訊息視窗載入的形式    /// </summary>    public enum LoadMode    {        /// <summary>        /// 警告        /// </summary>        Warning,        /// <summary>        /// 錯誤        /// </summary>        Error,        /// <summary>        /// 提示        /// </summary>        Prompt    }    /// <summary>    /// 訊息提示視窗    /// </summary>    public partial class FormMessageBox : Form    {        /// <summary>        /// 構造方法        /// </summary>        public FormMessageBox()        {            InitializeComponent();        }        #region ***********************字 段***********************        /// <summary>        /// 表單載入模式        /// </summary>        private static LoadMode FormMode = LoadMode.Prompt;        /// <summary>        /// 顯示的訊息本文        /// </summary>        private static string ShowMessage = null;        /// <summary>        /// 關閉視窗的定時器        /// </summary>        private Timer Timer_Close = new Timer();        [DllImportAttribute("user32.dll")]        private static extern bool AnimateWindow(IntPtr hwnd, int dwTime, int dwFlags);   // 該函數可以實現表單的動畫效果        public const Int32 AW_HOR_POSITIVE = 0x00000001;   // 自左向右顯示視窗。該標誌可以在滾動動畫和滑動動畫中使用。當使用AW_CENTER標誌時,該標誌將被忽略         public const Int32 AW_HOR_NEGATIVE = 0x00000002;   // 自右向左顯示視窗。當使用了 AW_CENTER 標誌時該標誌被忽略        public const Int32 AW_VER_POSITIVE = 0x00000004;   // 自頂向下顯示視窗。該標誌可以在滾動動畫和滑動動畫中使用。當使用AW_CENTER標誌時,該標誌將被忽略        public const Int32 AW_VER_NEGATIVE = 0x00000008;   // 自下向上顯示視窗。該標誌可以在滾動動畫和滑動動畫中使用。當使用AW_CENTER標誌時,該標誌將被忽略        public const Int32 AW_CENTER = 0x00000010;         // 若使用了AW_HIDE標誌,則使視窗向內重疊;若未使用AW_HIDE標誌,則使視窗向外擴充        public const Int32 AW_HIDE = 0x00010000;           // 隱藏視窗,預設則顯示視窗        public const Int32 AW_ACTIVATE = 0x00020000;       // 啟用視窗。在使用了AW_HIDE標誌後不要使用這個標誌        public const Int32 AW_SLIDE = 0x00040000;          // 使用滑動類型。預設則為滾動動畫類型。當使用AW_CENTER標誌時,這個標誌就被忽略        public const Int32 AW_BLEND = 0x00080000;          // 使用淡入效果。只有當hWnd為頂層視窗的時候才可以使用此標誌        #endregion*************************************************        #region ***********************方 法***********************        /// <summary>        /// 構造方法        /// </summary>        /// <param name="loadMode">載入模式</param>        /// <param name="message">訊息本文</param>        public static void Show(LoadMode loadMode, string message)        {            FormMode = loadMode;            ShowMessage = message;            FormMessageBox box = new FormMessageBox();            box.Show();        }        #endregion*************************************************        #region ***********************事 件***********************        /// <summary>        /// 表單載入事件        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void FormMessageBox_Load(object sender, EventArgs e)        {            this.lblTitle.Text = "提示";            if (FormMode == LoadMode.Error)            {                this.lblTitle.Text = "錯誤";                this.plShow.BackgroundImage = global::dataSource.Properties.Resources.error;    // 更換背景            }            else if (FormMode == LoadMode.Warning)            {                this.lblTitle.Text = "警告";                this.plShow.BackgroundImage = global::dataSource.Properties.Resources.warning;  // 更換背景            }            else            {                this.plShow.BackgroundImage = global::dataSource.Properties.Resources.Prompt;   // 更換背景            }            this.lblMessage.Text = ShowMessage;            int width = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width;            int height = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height;            int top = height - 35 - this.Height;            int left = width - this.Width - 5;            this.Top = top;            this.Left = left;            this.TopMost = true;            AnimateWindow(this.Handle, 500, AW_SLIDE + AW_VER_NEGATIVE);//開始表單動畫            this.ShowInTaskbar = false;            Timer_Close.Interval = 4000;            Timer_Close.Tick += new EventHandler(Timer_Close_Tick);            Timer_Close.Start();        }        /// <summary>        /// 關閉視窗的定時器響應事件        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void Timer_Close_Tick(object sender, EventArgs e)        {            Timer_Close.Stop();            this.Close();        }        /// <summary>        /// 視窗已經關閉        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void FormMessageBox_FormClosed(object sender, FormClosedEventArgs e)        {            AnimateWindow(this.Handle, 500, AW_SLIDE + AW_VER_POSITIVE + AW_HIDE);            Timer_Close.Stop();            Timer_Close.Dispose();        }        /// <summary>        /// 滑鼠移動在訊息框上        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void plShow_MouseMove(object sender, MouseEventArgs e)        {            this.Timer_Close.Stop();        }        /// <summary>        /// 滑鼠移動離開訊息框上        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void plShow_MouseLeave(object sender, EventArgs e)        {            this.Timer_Close.Start();        }

C#實現右下角彈窗

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.