All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
DataSet数据导入Excel的c#代码_[Asp.Net教程]
C#中常用的集合类型
asp.net2.0服务器控件之ImageButton控件
ASP.NET开发经验(5):,制作功能完善的安装程序_[Asp.Net教程]
ASP.Net生成后台脚本的问题的解决办法_[Asp.Net教程]
动态网页制作学习:PHP预定义变量_php资料_编程技术
ASP.NET从零起步设计网站全过程(9)_[Asp.Net教程]
GridView,中格式化整理_[Asp.Net教程]
基础知识:PHP连接mysql测试和配置_php资料_编程技术
php+mysql实现无限级分类_[PHP教程]
Reading number is top 10 pictures
世界五大海盗
中国处女图鉴2
移民小国也实惠2
Ashlynn Brooke show proud chest measurement1
China's family planning commission forced abortions 270 million newborns for 30 years
全球清廉国家排行
More attractive than sora aoi1
西班牙山村小景5
Female model behind the bitterness, often being overcharged4
Send some Valentine's day cartoon
Download software ranking
Tram sex maniac 2 (H) rar bag3
Adobe Flash Player(IE) 10.0.32.18 浏览器专用的FLASH插件
Unix video tutorial6
WebService在.NET中的实战应用教学视频 → 第5集
Unix video tutorial20
Eclipse 4.2.1 For Win32
matrix1
SP4 for SQL2000
Tram sex maniac 2 (H) rar bag15
WebService在.NET中的实战应用教学视频 → 第2集
qq published in(发表于) 2014/7/11 9:19:28 Edit(编辑)
C#中定义鼠标指针为指定的动画图标实例

C#中定义鼠标指针为指定的动画图标实例

C#中定义鼠标指针为指定的动画图标实例|方法

定义鼠标指针为指定的动画图标

在Windows窗体中,通过设置控件的属性无法将鼠标指针设置为动画图标的形式,如果要实现该功能,可以通过API函数LoadCursorFromFile和SetClassLong实现。这两个函数的声明代码如下:

[DllImport("user32", EntryPoint = "LoadCursorFromFile")]

public static extern int LoadCursorFromFile(string lpFileName);

[DllImport("user32", EntryPoint = "SetSystemCursor")]

public static extern void SetSystemCursor(int hcur, int i);

注意:调用API函数时,需要导入using System. Runtime. InteropServices命名空间。

示例

定义鼠标指针为指定的动画图标。

本示例中,程序运行时,当鼠标指针移动到窗体上时,鼠标指针显示动画效果。示例运行结果如图1所示。



图1 鼠标为指定的动画图标

private void frmPicut_Load(object sender, EventArgs e)

{

string reportPath = Application.StartupPath.Substring(0, Application.StartupPath.Substring(0,

Application.StartupPath.LastIndexOf("")).LastIndexOf(""));

reportPath += @"sl3210mouse.ani";

int cur = LoadCursorFromFile(reportPath);

SetSystemCursor(cur, 32512);

}

private void frmPicut_FormClosing(object sender, FormClosingEventArgs e)

{

int cur = LoadCursorFromFile(@"C:WINDOWSCursorsarrow_m.cur");

SetSystemCursor(cur, 32512);

}

完整程序代码如下:

★ ★★★★Form1.cs窗体代码文件完整程序代码★★★★★

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

namespace _2_03

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}

}

}

★ ★★★★Form1.Designer.cs窗体设计文件完整程序代码★★★★★

namespace _2_03

{

partial class Form1

{

///



/// 必需的设计器变量。

///


private System.ComponentModel.IContainer components = null;

///

/// 清理所有正在使用的资源。

///


/// 如果应释放托管资源,为 true;否则为 false。

protected override void Dispose(bool disposing)

{

if (disposing && (components != null))

{

components.Dispose();

}

base.Dispose(disposing);

}

#region Windows 窗体设计器生成的代码

///

/// 设计器支持所需的方法 - 不要

/// 使用代码编辑器修改此方法的内容。

///


private void InitializeComponent()

{

this.components = new System.ComponentModel.Container();

this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;

this.Text = "Form1";

}

#endregion

}

}

★ ★★★★frmPicut.cs窗体代码文件完整程序代码★★★★★

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

using System.Runtime.InteropServices;

namespace _2_03

{

public partial class frmPicut : Form

{

public frmPicut()

{

InitializeComponent();

}

[DllImport("user32", EntryPoint = "LoadCursorFromFile")]

public static extern int LoadCursorFromFile(string lpFileName);

[DllImport("user32", EntryPoint = "SetSystemCursor")]

public static extern void SetSystemCursor(int hcur, int i);

private void frmPicut_Load(object sender, EventArgs e)

{

string reportPath = Application.StartupPath.Substring(0, Application.StartupPath.Substring(0,

Application.StartupPath.LastIndexOf("")).LastIndexOf(""));

reportPath += @"mouse.ani";

int cur = LoadCursorFromFile(reportPath);

SetSystemCursor(cur, 32512);

}

private void frmPicut_FormClosing(object sender, FormClosingEventArgs e)

{

int cur = LoadCursorFromFile(Environment.SystemDirectory.Substring(0,Environment.SystemDirectory.LastIndexOf(""))+@"Cursorsarrow_m.cur");

SetSystemCursor(cur, 32512);

}

}

}

★ ★★★★frmPicut.Desigment.cs窗体设计文件完整程序代码★★★★★


添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.