Winform implemented in the lower right corner to remind the pop Popuo effect (with Codes)

Scenes

effect

 

 

Note:

Blog home page:
https://blog.csdn.net/badao_liumang_qizhi
public concern number of
programs overbearing ape
acquisition-related programming e-books, tutorials and push for free download.

achieve

Create a form form, and drag a button, a pop trigger button appears

 

 

And then create a page when the page is displayed as a pop, and add a Timer

 

 

For aesthetics, background images and set its close button Photos

 

 

Then enter their code

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace Popup.Controls
{
    partial class Frm_Popup : System.Windows.Forms.Form
    {

        #region 变量
        private InformStyle InfoStyle = InformStyle.Vanish;//定义变量为隐藏
        private System.Drawing.Rectangle Rect;// define a rectangular frame memory array 
        Private  BOOL isMouseMove = to false ; // whether the mobile in the form 
        static  Private Frm_Popup F_Popup = new new Frm_Popup (); // instantiate current form 
        #endregion 

        #region built-in properties
         ///  <Summary > 
        /// enumeration value defining a task notifier
         ///  </ Summary> // InformStyle 
        protected  enum InformStyle 
        { 
            ///  <Summary> 
            /// Hide
             ///  </ Summary> 
            Vanish = 0 ,
             // / <Summary> 
            /// Displaying
             ///  </ Summary> 
            Display = . 1 ,
             ///  <Summary> 
            /// significantly view
             ///  </ Summary> 
            the Displaying = 2 ,
             ///  <Summary> 
            // / hiding
             ///  </ Summary> 
            Vanishing = . 3 
        }         
        
        ///  <Summary> 
        /// Gets or sets the current operating state
         ///  </ Summary> 
        protected InformStyle InfoState 
        { 
            GET { return this.InfoStyle; }
            set { this.InfoStyle = value; }
        }
        #endregion

        public Frm_Popup()
  {
   this.InitializeComponent();
   this.timer1.Stop();//停止计时器
   //初始化工作区大小
   System.Drawing.Rectangle rect = System.Windows.Forms.Screen.GetWorkingArea(this);
   this.Rect = new System.Drawing.Rectangle( rect.Right - this.Width - 1, rect.Bottom - this.Height - 1, this.Width, the this .Height); 
  } 

        #region return of the current form instance
         ///  <Summary> 
        /// Returns an instance of this object
         ///  </ Summary> 
        ///  <Returns> </ Returns> 
        static  public Frm_Popup Instance () 
        { 
            return F_Popup; 
        } 
        #endregion 

        #region statement WinAPI
         ///  <Summary> 
        /// display form
         ///  </ Summary> 
        ///  <param name = "the hWnd"> </ param> 
        ///  <param name = "the nCmdShow"> </ param> 
        ///  <Returns> </ Returns>
        [DllImport("User32.dll " )]
         Private  static  extern Boolean the ShowWindow (IntPtr the hWnd, Int32 the nCmdShow);
         #endregion 

        #region method
         ///  <Summary> 
        /// Display Form
         ///  </ Summary> 
        public  void the Show () 
        { 
            Switch ( the this .InfoState) 
            { 
                Case InformStyle.Vanish: // form hide 
                    the this .InfoState = InformStyle.Displaying; // set the form to display the operation state of 
                    the this .SetBounds (rect.x, rect.y + rect.height , rect.width, 0 );// display Popup form, and place the bottom of the screen 
                    the ShowWindow ( the this .handle, . 4 ); // display form 
                    the this .timer1.Interval = 100 ; // set the time interval 100 
                    the this .timer1.Start (); // start timer 
                    BREAK ;
                 Case InformStyle.Display: // form displays 
                    the this .timer1.Stop (); // stop the timer 
                    the this .timer1.Interval = 5000 ; // set the time interval to 5000 
                    the this .timer1.Start (); // start timer 
                    BREAK ; 
            } 
        }
         #Endregion 

        #region event
         Private  void the timer1_Tick ( Object SENDER, System.EventArgs E) 
        { 
            Switch ( the this .InfoState) 
            { 
                Case InformStyle.Display: // display the current form 
                    the this .timer1.Stop (); // stop timer 
                    the this .timer1.Interval = 100 ; // set the time interval to 100 
                    IF ((! the this .isMouseMove)) // if the mouse is not moved form 
                        the this .InfoState = InformStyle.Vanishing; // set the current operation state is of the form hidden in 
                    this.timer1.Start (); // start timer 
                    BREAK ;
                 Case InformStyle.Displaying: // current form display 
                    IF ( the this .Height <= the this .Rect.Height - 12 is ) // when the form is not fully displayed 
                        the this .SetBounds (rect.x, the this .Top - 12 is , rect.width, the this .Height + 12 is ); // make the form constantly on the move 
                    the else 
                    { 
                        the this .timer1.Stop (); // stop the timer 
                        the this . SetBounds (rect.x, rect.y, rect.width, rect.height); //Set the current window boundaries 
                        the this .InfoState = InformStyle.Display; // set the current operating state of the display window of 
                        the this .timer1.Interval = 5000 ; // set the time interval to 5000 
                        the this .timer1.Start (); // starting a timer 
                    }
                     BREAK ;
                 Case InformStyle.Vanishing: // Hide the current form 
                    IF ( the this .isMouseMove) // if the mouse is moved form 
                        the this .InfoState = InformStyle.Displaying; // set the operating state of the form is displayed 
                    else 
                    { 
                        IF ( the this .Top <=the this .Rect.Bottom - 12 ) // If the form is not completely hide 
                            the this .SetBounds (rect.x, the this .Top + 12 , rect.width, the this .Height - 12 ); // make the form continued downward 
                        else 
                        { 
                            the this .hide (); // hides the current form 
                            the this .InfoState = InformStyle.Vanish; // set the operation state of the form as a hidden 
                        } 
                    } 
                    BREAK ; 
            } 
        } 

        Private  void Frm_Popup_MouseMove ( Object SENDER, the MouseEventArgs E)
        {
             the this .IsMouseMove = to true ; // when the mouse moved, the set to true 
        } 

        Private  void Frm_Popup_MouseLeave ( Object SENDER, EventArgs E) 
        { 
            the this .isMouseMove = to false ; // when the mouse is removed, the set to false 
        } 

        Private  void pictureBox1_Click ( Object SENDER, EventArgs E) 
        { 
            IF ( this .InfoState = InformStyle.Vanish)! // If not hidden state of the form 
            {
                 this .timer1.Stop (); // stop timer 
                this= InformStyle.Vanish .InfoState; // set the operating state of the form as a hidden 
                Base .hide (); // hides the current form 
            } 
        } 

        Private  void pictureBox1_MouseEnter ( Object SENDER, EventArgs E) 
        { 
            pictureBox1.Image = null ; 
            pictureBox1. Image = the Image.FromFile ( " Close1.bmp " ); 
        } 

        Private  void pictureBox1_MouseLeave ( Object SENDER, EventArgs E) 
        { 
            pictureBox1.Image = null ;
            pictureBox1.Image = Image.FromFile("Close2.bmp");
        }
        #endregion
    }
}

 

Download

https://download.csdn.net/download/BADAO_LIUMANG_QIZHI/12240463

Guess you like

Origin www.cnblogs.com/badaoliumangqizhi/p/12460543.html