C#显示动态光标和图标动态系统托盘

显示动态光标和图标的基本原理:
在计时器控件的Tick事件下
处理过程
把一系列图标或光标赋予给窗体的"iCON"属性,
以形成连续播放
的图标或光标
从而形成动态

1.在窗体上添加一个计时器"timer1"控件,
并准备一些图标1.ico,2.ico.........和光标
1.cur,2.cur.............
下面是源码:

 

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

namespace WindowsApplication4
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }


        //设置窗体属性showinTask=false

        //加notifyicon控件notifyIcon1,为控件notifyIcon1的属性Icon添加一个icon图标。

        int S;
        
        private void timer1_Tick(object sender, EventArgs e)
        {
            S++;
            if (S > 17)
                S = 0;
            //设置图标文件路径
            Icon icon = new Icon(@"F:/My Documents/Visual Studio 2005/Projects/动态图标/WindowsApplication4/ICO/" + S.ToString() + ".ico");
            this.Icon = icon;
          
            设置光标文件路径
            Cursor cur = new Cursor(@"F:/My Documents/Visual Studio 2005/Projects/动态图标/WindowsApplication4/cur/" + S.ToString() + ".cur");
            this.Cursor = cur;

             S++;
             if (S > 5)
                 S = 0;
             //设置图标文件路径
            Icon icon1 = new Icon(@"F:/My Documents/Visual Studio 2005/Projects/动态图标/WindowsApplication4/ICO/" + S.ToString() + ".ico");
            notifyIcon1.Icon = icon1;
        }
       //窗体加载时事件处理过程
        private void Form1_Load(object sender, EventArgs e)
        {
          
            timer1.Interval = 300;
            timer1.Enabled = true;
        }
        //添加窗体最小化事件(首先需要添加事件引用):
        private void Form1_SizeChanged(object sender, EventArgs e)
        {
            if (this.WindowState == FormWindowState.Minimized)
            {
                this.Hide();
                this.notifyIcon1.Visible = true;
            }
        }
        //添加点击图标事件(首先需要添加事件引用):
        private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            this.Visible = true;

            this.WindowState = FormWindowState.Normal;

            this.notifyIcon1.Visible = false;


        }

        private void label1_Click(object sender, EventArgs e)
        {

        }
                 // 可以给notifyIcon添加右键菜单:

                 //主窗体中拖入一个ContextMenu控件contextMenu1,点中控件,在上下文菜单中添加菜单,notifyIcon1的ContextMenu行为中选中contextMenu1作为上下文菜单。

                //(可以在子菜单中添加行为)


 

      
    }
}

源程序下载地址:
http://dl2.csdn.net/down4/20071008/08185203360.rar 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值