Einzelnen Beitrag anzeigen

Benutzerbild von phlux
phlux

Registriert seit: 4. Nov 2002
Ort: Witten
1.335 Beiträge
 
Delphi 6 Personal
 
#3

Re: Komponente verpennt Mausklick??

  Alt 8. Jun 2005, 19:36
Doch doch OnClick wird ausgelöst sonst würd ich nicht den Beep; hören

Hier mal der Code:

Delphi-Quellcode:
unit ImageButton;

interface

uses
  SysUtils, Classes, Controls, Windows, Graphics, Messages{, Dialogs};

type
  TButtonState = (bsNormal, bsHot, bsDown);
  TImageButton = class(TCustomControl)
  private
    { Private-Deklarationen }
    fGlyph: TBitmap;
    fButtonState: TButtonState;
    fMouseIn: Boolean;
    procedure SetGlyph(aGlyph: TBitmap);
    procedure SetButtonState(aState: TButtonState);
    procedure MouseEnter(var Msg: TMessage); message CM_MOUSEENTER;
    procedure MouseLeave(var Msg: TMessage); message CM_MOUSELEAVE;
    procedure MouseDown(var Msg: TMessage); message WM_LBUTTONDOWN;
    procedure MouseUp(var Msg: TMessage); message WM_LBUTTONUP;
  protected
    { Protected-Deklarationen }
    procedure Paint; override;
  public
    { Public-Deklarationen }
    constructor Create(aOwner: TComponent); override;
    destructor Destroy; override;
  published
    { Published-Deklarationen }
    property Glyph: TBitmap read fGlyph write SetGlyph;
    property ButtonState: TButtonState read fButtonState write SetButtonState;
    // Vererbte Properties
    property OnClick;
    property Align;
  end;

procedure Register;

implementation

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

constructor TImageButton.Create(aOwner: TComponent);
begin
  inherited Create(aOwner);
  fGlyph := TBitmap.Create;
  Width := 21;
  Height := 21;
  fButtonState := bsNormal;
  fMouseIn := False;
  Align := alRight;
end;

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

procedure TImageButton.SetGlyph(aGlyph: TBitmap);
begin
  if aGlyph <> fGlyph then
    fGlyph.Assign(aGlyph);
  invalidate;
end;

procedure TImageButton.Paint;
begin
  if fGlyph.Handle <> 0 then
  begin
    case fButtonState of
      bsNormal: begin
                  BitBlt(Canvas.Handle, 0, 0, Width, Height, fGlyph.Canvas.Handle, 0, 0, SRCCOPY);
                end;
      bsHot: begin
               BitBlt(Canvas.Handle, 0, 0, Width, Height, fGlyph.Canvas.Handle, fGlyph.Height * 1, 0, SRCCOPY);
             end;
      bsDown: begin
                BitBlt(Canvas.Handle, 0, 0, Width, Height, fGlyph.Canvas.Handle, fGlyph.Height * 2, 0, SRCCOPY);
              end;
    end;
  end;
  inherited Paint;
end;

procedure TImageButton.SetButtonState(aState: TButtonState);
begin
  if fButtonState <> aState then
    fButtonState := aState;
  invalidate;
end;

procedure TImageButton.MouseEnter(var Msg: TMessage);
begin
  if not (csDesigning in ComponentState) then
    SetButtonState(bsHot);
  fMouseIn := True;
  inherited;
end;

procedure TImageButton.MouseLeave(var Msg: TMessage);
begin
  if not (csDesigning in ComponentState) then
    SetButtonState(bsNormal);
  fMouseIn := False;
  inherited;
end;

procedure TImageButton.MouseDown(var Msg: TMessage);
begin
  if not (csDesigning in ComponentState) then
    SetButtonState(bsDown);
  inherited;
end;

procedure TImageButton.MouseUp(var Msg: TMessage);
begin
  if not (csDesigning in ComponentState) then
  begin
    if fMouseIn then SetButtonState(bsHot) else
      SetButtonState(bsNormal);
  end;
  inherited;
end;

end.
Ich vermute es liegt daran, dass ich bei den letzten 4 Prozeduren die Nachricht nicht richtig weitergebe, nachdem ich sie abgefangen habe
Christian "phlux" Arndt
  Mit Zitat antworten Zitat