Einzelnen Beitrag anzeigen

owolicious

Registriert seit: 14. Feb 2007
38 Beiträge
 
#8

Re: Shape Hintergrund transparent

  Alt 21. Feb 2007, 19:50
ist eine abgeleitete komponente von tcustomcontrol in der die paint funktion einfach überschrieben bzw erweitert wurde... hab einfach auf das canvas einen pfeil gemalt...

Delphi-Quellcode:
unit Pfeil;

interface

uses
  SysUtils, Classes, Controls, Windows, Graphics;

type
  TMyPfeil = class(TCustomControl)
  private
    { Private declarations }
    FSelected : Boolean;
    procedure SetSelection(Value : Boolean);
  protected
    { Protected declarations }
     protected procedure Paint();override;
  public
    { Public declarations }
  published
    { Published declarations }
    property Selected: Boolean read FSelected write SetSelection;
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('Samples', [TMyPfeil]);
end;

procedure TMyPfeil.SetSelection(Value : Boolean);
begin
  FSelected := Value;
  if Value = True then
    Self.DoubleBuffered := true
  else
    Self.DoubleBuffered := False;
  Invalidate;
end;

procedure TMyPfeil.Paint;
begin
  inherited;

// Canvas.Brush.Color := $00654987;
// Canvas.Fillrect(Rect(0,0,self.Width, self.Height));

  Canvas.Brush.Color := $00000000;
  Canvas.Polygon([
    Point(self.Width-18,3),
    Point(self.Width - 10, Trunc(self.Height / 2)),
    Point(self.Width-18,self.Height-4)
  ]);

  Canvas.Pen.Color := $00000000;
  Canvas.MoveTo(8, Trunc(self.Height /2));
  Canvas.LineTo(self.Width - 4, Trunc(self.Height / 2));

  if self.Selected = True then begin
    Canvas.Pen.Color := $00000000;
    Canvas.Brush.Color := $00FFFFFF;

    Canvas.Rectangle(0, Trunc(self.Height /2)-4, 8, Trunc(self.Height /2)+4);
    Canvas.Rectangle(self.Width - 8, Trunc(self.Height /2)-4, self.Width, Trunc(self.Height /2)+4);
  end;
end;

end.
  Mit Zitat antworten Zitat