如何使单鼠标进入某按钮范围时自动改变按钮上面的图标(按钮的NumGlyphs=2以上)?(100分)

  • 主题发起人 主题发起人 czdd
  • 开始时间 开始时间
cxdd: 不需要使用loadfromfile也可以呀,可以使用IMAGELIST代替。不过,
如果鼠标移动速度太快会侦测不到事件的。:-(


 
可怜的我,连TToolButton控件都找不到!
请教delphiwolf:
TToolBar.Images/TToolBar.HotImages 如何设置?

 
1、在Win32页找ToolBar放1个,ImageList放3个。
2、选中ToolBar1,右键单击,选New Button。
3、选中ImageList1,双击,点Add...,ImageList2,ImageList3,依次设置。
4、选中ToolBar1,设置Images为ImageList1,HotImages为ImageList2,DisabledImages为ImageList3。

//Images是Button正常时的图,HotImages是鼠标进入Button时的图,DisabledImages是ToolButton.Enabled=False时的图.
//Ok?
 
怎么就非要用ToolButton?
1.ImageList在ToolBar中的表现有些NT下和98下不一样;
2.ImageList如果图像做大就不好玩了(如360x100)。
还是看我的吧(其实和Another_eye的方法是一回事)。

unit ImageBtns;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;

type
TImageButton = class(TGraphicControl)
private
{ Private declarations }
FGlyph: TBitmap;
FOnMouseEnter : TNotifyEvent;
FOnMouseLeave : TNotifyEvent;
procedure SetGlyph(Value: TBitmap);
procedure CMMouseEnter(var Msg: TMessage); message CM_MOUSEENTER;
procedure CMMouseLeave(var Msg: TMessage); message CM_MOUSELEAVE;
protected
{ Protected declarations }
procedure DoMouseEnter; virtual;
procedure DoMouseLeave; virtual;
public
{ Public declarations }
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure Paint; override;
published
{ Published declarations }
property Glyph: TBitmap read FGlyph write SetGlyph;
property OnMouseEnter: TNotifyEvent read FOnMouseEnter write FOnMouseEnter;
property OnMouseLeave: TNotifyEvent read FOnMouseLeave write FOnMouseLeave;
property PopupMenu;
property ShowHint;
property Visible;
property OnClick;
property OnDblClick;
property OnDragDrop;
property OnDragOver;
property OnEndDrag;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
end;

procedure Register;

implementation

constructor TImageButton.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FGlyph := TBitmap.Create;
SetGlyph(nil);
end;

destructor TImageButton.Destroy;
begin
FGlyph.Free;
inherited Destroy;
end;

procedure TImageButton.SetGlyph(Value: TBitmap);
begin
FGlyph.Width := 16;
FGlyph.Height := 16;
if Value <> nil then begin
FGlyph.Assign(Value);
Width := FGlyph.Width div 2;
Height := FGlyph.Height;
end;
Invalidate;
end;

procedure TImageButton.CMMouseEnter(var Msg: TMessage);
begin
DoMouseEnter;
end;

procedure TImageButton.CMMouseLeave(var Msg: TMessage);
begin
DoMouseLeave;
end;

procedure TImageButton.DoMouseEnter;
begin
if Assigned(FOnMouseEnter) then FOnMouseEnter(Self)
else Canvas.CopyRect(ClientRect, FGlyph.Canvas, Rect(Width, 0, Width * 2, Height))
end;

procedure TImageButton.DoMouseLeave;
begin
if Assigned(FOnMouseLeave) then FOnMouseLeave(Self)
else Invalidate;
end;

procedure TImageButton.Paint;
begin
Canvas.CopyRect(ClientRect, FGlyph.Canvas, Rect(0, 0, Width, Height))
end;

procedure Register;
begin
RegisterComponents('Bartons', [TImageButton]);
end;

end.
 
barton的控件棒极了!!这正是我想要的,如果能和transbtn结合,
那就完美无缺了!!
 

Similar threads

S
回复
0
查看
828
SUNSTONE的Delphi笔记
S
S
回复
0
查看
760
SUNSTONE的Delphi笔记
S
D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
后退
顶部