Ich bin dabei meine erste eigene Komponente zu entwickeln. Leider wird sie auf einer Form mit der Größe (0,0) eingefügt. Außerdem wird sie nicht gezeichnet, sie bekommt die Farbe der Form, je nach dem was ich dort einstelle. Ich bitte um Hilfe oder entsprechende Links.
Code: Alles auswählen
unit UFreeListBox;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, ExtCtrls,
LMessages, Types;
type
TFreeListBox = class(TCustomControl)
private
FBevel: TBevelCut;
FBevelWidth: TBevelWidth;
procedure SetBevel(const AValue: TBevelCut);
procedure SetBevelWidth(const AValue: TBevelWidth);
protected
class function GetControlClassDefaultSize: TPoint; override; // damit hatte ich gehofft die Größe beim Einfügen im Form-Editor setzen zu können
procedure Paint; override;
public
published
property Bevel: TBevelCut read FBevel write SetBevel;
property BevelWidth: TBevelWidth read FBevelWidth write SetBevelWidth;
property Color default clWindow; // new default - sollte doch so gehen, oder?
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Eigene',[TFreeListBox]);
end;
procedure TFreeListBox.SetBevel(const AValue: TBevelCut);
begin
if Bevel <> AValue then begin
FBevel := AValue;
Perform(CM_BORDERCHANGED, 0, 0); // übernommen von TPanel
end;
end;
procedure TFreeListBox.SetBevelWidth(const AValue: TBevelWidth);
begin
if FBevelWidth <> AValue then begin
FBevelWidth := AValue;
Perform(CM_BORDERCHANGED, 0, 0); // übernommen von TPanel
end;
end;
class function TFreeListBox.GetControlClassDefaultSize: TPoint; // damit hatte ich gehofft die Größe beim Einfügen im Form-Editor setzen zu können
begin
Result.X:=100;
Result.Y:=80;
end;
procedure TFreeListBox.Paint;
var
ARect: TRect;
begin
ARect := GetClientRect;
if (Bevel <> bvNone) and (BevelWidth > 0) then begin
Canvas.Frame3d(ARect, BevelWidth, Bevel);
InflateRect(ARect, -BevelWidth, -BevelWidth);
end;
Canvas.Brush.Color := Color;
Canvas.FillRect(ARect);
inherited Paint; // OnPaint einbinden
end;
end.