美文网首页程序员
记一次WinForm开发——WinForm气泡提示

记一次WinForm开发——WinForm气泡提示

作者: 七三先生73sir | 来源:发表于2019-07-15 19:26 被阅读1次

    最终效果


    图片.png

    本实例实现时主要用到了NotifyIcon控件的ShowBalloonTip方法。
    NotifyIcon控件表示在通知区域中创建图标的控件,其ShowBallonTip方法用于在任务栏中持续显示具有指定标题、文本和图标的气球提示指定的时间,该方法的语法格式如下:

    Void NotifyIcon.ShowBalloonTip(int timeout,string tipTitle,string tipText,ToolTipIcon tipIcon);
    //timeout 表示气球提示显示的时间长度
    //tipTitle 表示要在气球提示上显示的标题
    //tipText 表示要在气球提示上显示的文本
    //tipIcon 表示气球提示的图标
    

    步骤

    • 新建一个WinForm窗体类
    • 在该窗体添加button控件和notifyIcon控件
    • 设置button控件和notifyIcon控件的属性

    代码

    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;
    
    namespace 实例205实现气泡提示窗口
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                this.notifyIcon1.Visible = true;//设置提示控件可见
                this.notifyIcon1.ShowBalloonTip(1000,"当前时间:",DateTime.Now.ToLocalTime().ToString(),ToolTipIcon.Info);//显示气泡提示
            }
    
            private void button2_Click(object sender, EventArgs e)
            {
                this.notifyIcon1.Visible = false;
            }
    
            private void notifyIcon1_MouseMove(object sender, MouseEventArgs e)//气泡快消失时,鼠标移向气泡将重新显示
            {
                this.notifyIcon1.ShowBalloonTip(1000, "加油!", "烁烁和乐乐是一辈子的好兄弟", ToolTipIcon.Info);//显示气泡提示
                //this.notifyIcon1.ShowBalloonTip(1000, "当前时间:", DateTime.Now.ToLocalTime().ToString(), ToolTipIcon.Info);//显示气泡提示
            }
    
        
            private void button3_Click(object sender, EventArgs e)
            {
                this.notifyIcon1.Visible = true;//设置提示控件可见
                this.notifyIcon1.ShowBalloonTip(1000, "加油!", "烁烁和乐乐是一辈子的好兄弟", ToolTipIcon.Info);//显示气泡提示
            }
        }
    }
    

    相关文章

      网友评论

        本文标题:记一次WinForm开发——WinForm气泡提示

        本文链接:https://www.haomeiwen.com/subject/faeokctx.html