zoukankan      html  css  js  c++  java
  • WinFrom 右下角弹出提示框


        1. //Download by http://www.codefans.net
        2.  
           
        3.  
          using System;
        4.  
          using System.Collections.Generic;
        5.  
          using System.ComponentModel;
        6.  
          using System.Data;
        7.  
          using System.Drawing;
        8.  
          using System.Linq;
        9.  
          using System.Text;
        10.  
          using System.Windows.Forms;
        11.  
          using System.Runtime.InteropServices;
        12.  
           
        13.  
          namespace Popup.Controls
        14.  
          {
        15.  
          partial class Frm_Popup : System.Windows.Forms.Form
        16.  
          {
        17.  
           
        18.  
           
        19.  
          private InformStyle InfoStyle = InformStyle.Vanish;//定义变量为隐藏
        20.  
          private System.Drawing.Rectangle Rect;//定义一个存储矩形框的数组
        21.  
          private bool isMouseMove = false;//是否在窗体中移动
        22.  
          static private Frm_Popup F_Popup = new Frm_Popup();//实例化当前窗体
        23.  
           
        24.  
           
        25.  
          /// <summary>
        26.  
          /// 定义一个任务通知器的枚举值
        27.  
          /// </summary>//InformStyle
        28.  
          protected enum InformStyle
        29.  
          {
        30.  
          /// <summary>
        31.  
          /// 隐藏
        32.  
          /// </summary>
        33.  
          Vanish = 0,
        34.  
          /// <summary>
        35.  
          /// 显视
        36.  
          /// </summary>
        37.  
          Display = 1,
        38.  
          /// <summary>
        39.  
          /// 显视中
        40.  
          /// </summary>
        41.  
          Displaying = 2,
        42.  
          /// <summary>
        43.  
          /// 隐藏中
        44.  
          /// </summary>
        45.  
          Vanishing = 3
        46.  
          }
        47.  
           
        48.  
          /// <summary>
        49.  
          /// 获取或设置当前的操作状态
        50.  
          /// </summary>
        51.  
          protected InformStyle InfoState
        52.  
          {
        53.  
          get { return this.InfoStyle; }
        54.  
          set { this.InfoStyle = value; }
        55.  
          }
        56.  
           
        57.  
           
        58.  
          public Frm_Popup()
        59.  
          {
        60.  
          this.InitializeComponent();
        61.  
          this.timer1.Stop();//停止计时器
        62.  
          //初始化工作区大小
        63.  
          System.Drawing.Rectangle rect = System.Windows.Forms.Screen.GetWorkingArea(this);
        64.  
          this.Rect = new System.Drawing.Rectangle( rect.Right - this.Width - 1, rect.Bottom - this.Height - 1, this.Width, this.Height );
        65.  
          }
        66.  
           
        67.  
           
        68.  
          /// <summary>
        69.  
          /// 返回此对象的实例
        70.  
          /// </summary>
        71.  
          /// <returns></returns>
        72.  
          static public Frm_Popup Instance()
        73.  
          {
        74.  
          return F_Popup;
        75.  
          }
        76.  
           
        77.  
           
        78.  
          /// <summary>
        79.  
          /// 显示窗体
        80.  
          /// </summary>
        81.  
          /// <param name="hWnd"></param>
        82.  
          /// <param name="nCmdShow"></param>
        83.  
          /// <returns></returns>
        84.  
          [DllImport("user32.dll")]
        85.  
          private static extern Boolean ShowWindow(IntPtr hWnd, Int32 nCmdShow);
        86.  
           
        87.  
           
        88.  
          /// <summary>
        89.  
          /// 显示窗体
        90.  
          /// </summary>
        91.  
          public void Show()
        92.  
          {
        93.  
          switch (this.InfoState)
        94.  
          {
        95.  
          case InformStyle.Vanish://窗体隐藏
        96.  
          this.InfoState = InformStyle.Displaying;//设置窗体的操作状态为显示中
        97.  
          this.SetBounds(Rect.X, Rect.Y + Rect.Height, Rect.Width, 0);//显示Popup窗体,并放置到屏幕的底部
        98.  
          ShowWindow(this.Handle, 4);//显示窗体
        99.  
          this.timer1.Interval = 100;//设置时间间隔为100
        100.  
          this.timer1.Start();//启动计时器
        101.  
          break;
        102.  
          case InformStyle.Display://窗体显示
        103.  
          this.timer1.Stop();//停止计时器
        104.  
          this.timer1.Interval = 5000;//设置时间间隔为5000
        105.  
          this.timer1.Start();//启动记时器
        106.  
          break;
        107.  
          }
        108.  
          }
        109.  
           
        110.  
           
        111.  
          private void timer1_Tick(object sender, System.EventArgs e)
        112.  
          {
        113.  
          switch (this.InfoState)
        114.  
          {
        115.  
          case InformStyle.Display://显示当前窗体
        116.  
          this.timer1.Stop();//停止计时器
        117.  
          this.timer1.Interval = 100;//设置时间间隔为100
        118.  
          if (!(this.isMouseMove))//如果鼠标不在窗体中移动
        119.  
          this.InfoState = InformStyle.Vanishing;//设置当前窗体的操作状态为隐藏中
        120.  
          this.timer1.Start();//启动计时器
        121.  
          break;
        122.  
          case InformStyle.Displaying://当前窗体显示中
        123.  
          if (this.Height <= this.Rect.Height - 12)//当窗体没有完全显示时
        124.  
          this.SetBounds(Rect.X, this.Top - 12, Rect.Width, this.Height + 12);//使窗体不断上移
        125.  
          else
        126.  
          {
        127.  
          this.timer1.Stop();//停止计时器
        128.  
          this.SetBounds(Rect.X, Rect.Y, Rect.Width, Rect.Height);//设置当前窗体的边界
        129.  
          this.InfoState = InformStyle.Display;//设置当前窗体的操作状态为显示
        130.  
          this.timer1.Interval = 5000;//设置时间间隔为5000
        131.  
          this.timer1.Start();//启动计时器
        132.  
          }
        133.  
          break;
        134.  
          case InformStyle.Vanishing://隐藏当前窗体
        135.  
          if (this.isMouseMove)//如果鼠标在窗体中移动
        136.  
          this.InfoState = InformStyle.Displaying;//设置窗体的操作状态为显示
        137.  
          else
        138.  
          {
        139.  
          if (this.Top <= this.Rect.Bottom - 12)//如果窗体没有完全隐藏
        140.  
          this.SetBounds(Rect.X, this.Top + 12, Rect.Width, this.Height - 12);//使窗体不断下移
        141.  
          else
        142.  
          {
        143.  
          this.Hide();//隐藏当前窗体
        144.  
          this.InfoState = InformStyle.Vanish;//设置窗体的操作状态为隐藏
        145.  
          }
        146.  
          }
        147.  
          break;
        148.  
          }
        149.  
          }
        150.  
           
        151.  
           
        152.  
          private void Frm_Popup_MouseMove(object sender, MouseEventArgs e)
        153.  
          {
        154.  
          this.isMouseMove = true;//当鼠标移入时,设为true
        155.  
          }
        156.  
           
        157.  
           
        158.  
          private void Frm_Popup_MouseLeave(object sender, EventArgs e)
        159.  
          {
        160.  
          this.isMouseMove = false;//当鼠标移出时,设为false
        161.  
          }
        162.  
           
        163.  
           
        164.  
          private void pictureBox1_Click(object sender, EventArgs e)
        165.  
          {
        166.  
          if (this.InfoState != InformStyle.Vanish)//如果窗体的状态不是隐藏
        167.  
          {
        168.  
          this.timer1.Stop();//停止计时器
        169.  
          this.InfoState = InformStyle.Vanish;//设置窗体的操作状态为隐藏
        170.  
          base.Hide();//隐藏当前窗体
        171.  
          }
        172.  
          }
        173.  
           
        174.  
           
        175.  
          private void pictureBox1_MouseEnter(object sender, EventArgs e)
        176.  
          {
        177.  
          pictureBox1.Image = null;
        178.  
          pictureBox1.Image = Image.FromFile("Close1.bmp");
        179.  
          }
        180.  
           
        181.  
           
        182.  
          private void pictureBox1_MouseLeave(object sender, EventArgs e)
        183.  
          {
        184.  
          pictureBox1.Image = null;
        185.  
          pictureBox1.Image = Image.FromFile("Close2.bmp");
        186.  
          }
        187.  
          }
        188.  
          }
  • 相关阅读:
    实用机器人设计(六)-建图,导航和路径规划
    实用机器人设计(五)-机器人电机功率选择和减速箱传动比设计
    实用机器人设计(四)-电机和驱动系统基础原理
    实用机器人设计(三)-计算机视觉
    Git 提交文件到Github
    爬虫框架Scrapy
    scrapy终端与核心组件
    图像识别与文字处理
    存储爬虫数据--Mongodb
    并发下载
  • 原文地址:https://www.cnblogs.com/ljsjxr/p/11837623.html
Copyright © 2011-2022 走看看