Einzelnen Beitrag anzeigen

Benutzerbild von Luckie
Luckie

Registriert seit: 29. Mai 2002
37.621 Beiträge
 
Delphi 2006 Professional
 
#1

Eigene Image-Komponente mit Hover-Effekt

  Alt 13. Aug 2007, 16:14
Ich habe die TImage-Komponente im eine Mouse-Hover Eigenschaft usw. erweitert. Hier mal eben der Quellcode:

Delphi-Quellcode:
type
  TDWImage = class(TImage)
  private
    { Private declarations }
    FVersion: String;
    FPictureNormal: TPicture;
    FPictureDown: TPicture;
    FPictureOver: TPicture;
    FPictureDisabled: TPicture;
    procedure SetPictureDown(Value: TPicture);
    procedure SetPictureOver(Value: TPicture);
    procedure SetPictureDisabled(Value: TPicture);
    procedure MouseOver(var Msg: TMessage); message CM_MOUSEENTER;
    procedure MouseLeave(var Msg: TMessage); message CM_MOUSELEAVE;
  protected
    { Protected declarations }
    procedure SetEnabled(Value: Boolean); override;
    procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
    procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
// procedure SetPicture(Pic: TPicture);
  public
    { Public declarations }
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  published
    { Published declarations }
    property Version: String read FVersion;
    property PictureDown: TPicture read FPictureDown write SetPictureDown;
    property PictureOver: TPicture read FPictureOver write SetPictureOver;
    property PictureDisabled: TPicture read FPictureDisabled write SetPictureDisabled;
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('Datawerk', [TDWImage]);
end;

{ TDWImage }

constructor TDWImage.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  FVersion := '1.0.0.3';
  FPictureNormal := TPicture.Create;
  FPictureDown := TPicture.Create;
  FPictureOver := TPicture.Create;
  FPictureDisabled := TPicture.Create;
end;

destructor TDWImage.Destroy;
begin
  inherited;
end;

procedure TDWImage.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  inherited MouseDown(Button, Shift, X, Y);
  Picture.Assign(FPictureDown);
end;

procedure TDWImage.MouseLeave(var Msg: TMessage);
begin
  if (Msg.Msg = CM_MOUSELEAVE) and (Enabled) then
  begin
    Picture.Assign(FPictureNormal);
  end;
end;

procedure TDWImage.MouseOver(var Msg: TMessage);
begin
  if (Msg.Msg = CM_MOUSEENTER) and (Enabled) then
  begin
    Picture.Assign(FPictureOver);
  end;
end;

procedure TDWImage.MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  inherited MouseUp(Button, Shift, X, Y);
  Picture.Assign(FPictureNormal);
end;

procedure TDWImage.SetEnabled(Value: Boolean);
begin
  inherited;
  if Value then
  begin
    if FPictureNormal = nil then
      ShowMessage('FPictureNormal ist nil')
    else
      Picture.Assign(FPictureNormal)
  end
  else
  begin
    Picture.Assign(FPictureDisabled);
  end;
end;

//procedure TDWImage.SetPicture(Pic: TPicture);
//begin
// Self.Picture := Pic;
// FPictureNormal.Assign(Pic);
//end;

procedure TDWImage.SetPictureDisabled(Value: TPicture);
begin
  FPictureDisabled.Assign(Value);
end;

procedure TDWImage.SetPictureDown(Value: TPicture);
begin
  FPictureDown.Assign(Value);
end;

procedure TDWImage.SetPictureOver(Value: TPicture);
begin
  FPictureOver.Assign(Value);
end;
Jetzt mustste ich aber feststellen, dass wenn sich im Code die Eigenschaft Enabled ändert, dann kein Image mehr angezeigt wird. Es ist einfach leer. Während hingegen, wenn ich dies im OI tue und allen Bildern ein Image zugewiesen habe, passiert dies nicht.
Woran kann das liegen?
Michael
Ein Teil meines Codes würde euch verunsichern.
  Mit Zitat antworten Zitat