procedure Register; begin RegisterComponents('jysoft', [TJyImageButton]); end; function GetCurrentPath: string; var current_path: string; begin current_path := ExtractFilePath(application.ExeName); if current_path[length(current_path)] <> '\' then current_path := current_path + '\'; result := current_path; end; constructor TJyImageButton.Create(AOwner: TComponent); begin inherited Create(AOwner); FNormalGlyph := TPicture.Create; FHotGlyph := TPicture.Create; FDisabledGlyph:= TPicture.Create; tag:=99; AutoSize:=True; fstate:=0; fstate0:=-1; f_loadimage:=False; ffilename:=''; Cursor:=crHandPoint; ftimer := TTimer.Create(Self); ftimer.Enabled := False; ftimer.Interval := 1; ftimer.OnTimer := mydispaly; FChangeImage:=false; if (csDesigning in ComponentState) then ftimer.Enabled := True; end;
destructor TJyImageButton.Destroy; begin FNormalGlyph.Free; FHotGlyph.Free; FDisabledGlyph.Free; ftimer.free; inherited Destroy; end; procedure TJyImageButton.mydispaly(Sender: TObject); begin ftimer.Enabled := False; refresh; end; procedure TJyImageButton.myGetPicture(pic:TPicture;pt:string); var fn,tmpfn,imgfn,path: string; i: integer; begin fn := Trim(ffilename); if fn='' then fn:=Name; i := Pos('_', fn); if i > 0 then fn := Copy(fn, i + 1, length(fn)); imgfn:=''; path:=GetCurrentpath+pt; tmpfn:=path + fn + '.jpg'; if FileExists(tmpfn) then begin imgfn:=tmpfn; end; tmpfn:=path + fn + '.gif'; if imgfn='' then if FileExists(tmpfn) then begin imgfn:=tmpfn; end; tmpfn:=path + fn + '.bmp'; if imgfn='' then if FileExists(tmpfn) then begin imgfn:=tmpfn; end; tmpfn:=path + fn + '.png'; if imgfn='' then if FileExists(tmpfn) then begin imgfn:=tmpfn; end; if imgfn<>'' then begin pic.LoadFromFile(imgfn); end; end; procedure TJyImageButton.Paint; begin if Enabled=false then FState:=2 else begin if FState<>1 then FState:=0; end; if (csDesigning in ComponentState) = false then if f_loadimage=false then begin myGetPicture(FNormalGlyph,'images\button\normal\'); myGetPicture(FHotGlyph,'images\button\hot\'); myGetPicture(FDisabledGlyph,'images\button\Disabled\'); f_loadimage:=True; end; if (csDesigning in ComponentState) then begin fstate:=0; end; if fstate0<>fstate then begin fstate0:=fstate; if fstate=0 then begin if FNormalGlyph.Graphic<>nil then Picture.Assign(FNormalGlyph); end; if fstate=1 then begin if FHotGlyph.Graphic<>nil then Picture.Assign(FHotGlyph); end; if fstate=2 then begin if FDisabledGlyph.Graphic<>nil then Picture.Assign(FDisabledGlyph) else if FNormalGlyph.Graphic<>nil then Picture.Assign(FNormalGlyph); end; end; inherited; end; procedure TJyImageButton.MyCMMouseLeave(var Message: TMessage); begin inherited; if (csDesigning in ComponentState) then Exit; if Enabled=False then Exit; if FNormalGlyph.Graphic<>nil then if FChangeImage then self.Picture.Assign(FNormalGlyph); fstate:=0; if Assigned(FOnMouseLeave) then FOnMouseLeave(Self); end;
procedure TJyImageButton.MyCMMouseEnter(var Message: TMessage); begin inherited; if (csDesigning in ComponentState) then Exit; if Enabled=False then Exit; if FhotGlyph.Graphic<>nil then if FChangeImage then self.Picture.Assign(FhotGlyph); fstate:=1; if Assigned(FOnMouseEnter) then FOnMouseEnter(Self); end; procedure TJyImageButton.SetNormalGlyph(Value: TPicture); begin FNormalGlyph.Assign(Value); fstate0:=-1; Invalidate; end;
procedure TJyImageButton.SetHotGlyph(Value: TPicture); begin FHotGlyph.Assign(Value); fstate0:=-1; Invalidate; end; procedure TJyImageButton.SetDisabledGlyph(Value: TPicture); begin FDisabledGlyph.Assign(Value); fstate0:=-1; Invalidate; end; end.
----------------------------------------------
qq:171833017,靖源软件http://www.dxmylove.com