使用自定义的光标
在delphi中有很多系统定义好的光标供我们来使用,但是某些时候我们也希望使用自己的光标来增加程序的趣味性或实用性。下面我就来介绍下怎么使用自己的光标。其主要原理是使用资源文件(*.res),资源文件制作的工具为delphi自带的Image Editor。
1.在开始菜单中找到delphi的安装程序,其中就有Image Editor,打开。 依次为File-New-Resource File,这时就新建了一个资源文件右键contents-New Cursor来创建一个光标,右键创建的cursor可以进行重命名、删除等操作。这时命名为"CRMYARROW"。双击打开该光标,随便画一个光标。
2.关闭光标文件。这时选择File-Save来进行资源文件的保存。自定义的资源文件必须与项目文件放在同一个目录,这样编译器才什么找到这个资源文件。
3.你可以在想更换光标的时候来进行加入以下代码,这时我选择了在窗体创建的时候来加载。完整代码如下:
unit Unit4;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;
const
crMyCursor = 9; //定义光标
type
TForm4 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form4: TForm4;
implementation
{$R *.dfm}
{$R myRes.res} //加入资源文件
procedure TForm4.FormCreate(Sender: TObject);
begin
//改变光标
Screen.Cursors[crMyCursor] := LoadCursor(HInstance,'CRMYARROW'); //注意这个名称一定要大写
Screen.Cursor := crMyCursor;
end;
end.
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;
const
crMyCursor = 9; //定义光标
type
TForm4 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form4: TForm4;
implementation
{$R *.dfm}
{$R myRes.res} //加入资源文件
procedure TForm4.FormCreate(Sender: TObject);
begin
//改变光标
Screen.Cursors[crMyCursor] := LoadCursor(HInstance,'CRMYARROW'); //注意这个名称一定要大写
Screen.Cursor := crMyCursor;
end;
end.

浙公网安备 33010602011771号