Thema: Delphi Sechseckige Komponente

Einzelnen Beitrag anzeigen

Benutzerbild von SirThornberry
SirThornberry
(Moderator)

Registriert seit: 23. Sep 2003
Ort: Bockwen
12.235 Beiträge
 
Delphi 2006 Professional
 
#14

Re: Sechseckige Komponente

  Alt 19. Mai 2005, 21:54
hier mal eine Sechseckkomponente (farbe im Create weg machen und dann kannst du davon ableiten)
Delphi-Quellcode:
  TSechsEck = class(TCustomControl)
  protected
    procedure SetParent(AParent: TWinControl); override;
  public
    constructor Create(AOwner: TComponent); override;
    procedure SetBounds(ALeft, ATop, AWidth, AHeight: Integer); override;
  end;

constructor TSechsEck.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  Color := clBlue;
  SetBounds(Left, Top, 100, 100);
end;

procedure TSechsEck.SetBounds(ALeft, ATop, AWidth, AHeight: Integer);
var LPoints: Array[0..5] of TPoint;
    LPart: Integer;
begin
  if Assigned(Parent) then
  begin
    LPart := Round(AHeight / 4);
    LPoints[0] := Point(AWidth div 2 - 1, 0);
    LPoints[1] := Point(AWidth - 1, LPart);
    LPoints[2] := Point(AWidth - 1, LPart * 3);
    LPoints[3] := Point(AWidth div 2 - 1, AHeight - 1);
    LPoints[4] := Point(0, LPart * 3);
    LPoints[5] := Point(0, LPart);
    SetWindowRgn(Handle, CreatePolygonRgn(LPoints, length(LPoints), ALTERNATE), True);
  end;
  inherited SetBounds(ALeft, ATop, AWidth, AHeight);
end;

procedure TSechsEck.SetParent(AParent: TWinControl);
begin
  inherited SetParent(AParent);
  if Assigned(Parent) then
    SetBounds(Left, Top, Width, Height);
end;
Jens
Mit Source ist es wie mit Kunst - Hauptsache der Künstler versteht's
  Mit Zitat antworten Zitat