您的位置:首页 > 编程语言 > C#

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

2007-12-10 10:49 465 查看
显示动态光标和图标的基本原理:
在计时器控件的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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: