Tach erstma..
Ich bin grad dran mir eine eigene Visuelle Komponente zu erschaffen.
Es soll einen Button geben...
Na jedenfalls wollte ich TColorPropery zum einstellen der Farben einbinden und das ist irgendwie nicht ganz ohne...
Ich muss die Komponente enzwei teilen, damit ich die Komponente später verwenden kann. Ist irgendwie neu,
damit man TColorProperty nicht während der Laufzeit verwenden darf (Typisch Windows).
Hier mein abgehalfterter Code: (Was mach ich falsch?)
Datei: EButton.pas
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86:
| unit EButton;
interface
uses SysUtils, Classes, Controls, StdCtrls, Graphics;
type TEButton = class(TCustomControl) private FFont : TFont; protected procedure Paint; override; public constructor Create(AOwner: TComponent); override; destructor Destroy; override; published property Font: TFont read FFont write FFont; end;
procedure Register;
implementation
procedure Register; begin RegisterComponents('RComponents', [TEButton]); end;
constructor TEButton.Create(AOwner: TComponent); begin inherited Create(AOwner); FFont:=TFont.Create; end;
destructor TEButton.Destroy; begin FFont.Free; inherited Destroy; end;
procedure TEButton.Paint; begin inherited; if csDesigning in ComponentState then begin Canvas.Brush.Style := bsSolid; Canvas.Brush.Color := clblue; Canvas.Pen.Color := clblack; Canvas.Rectangle(0,0,width,height); canvas.Font := FFont; canvas.TextOut((width - Canvas.TextWidth(Name)) div 2,(height - Canvas.TextHeight(Name)) div 2,name);
exit; end;
Canvas.Brush.Style := bsSolid; Canvas.Brush.Color := clblue; Canvas.Pen.Color := clblack; Canvas.Rectangle(0,0,width,height); canvas.Font := FFont; canvas.TextOut((width - Canvas.TextWidth(Name)) div 2,(height - Canvas.TextHeight(Name)) div 2,name);
exit;end; end. |
Datei: EButton_API.pas
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43:
| unit EButton_API;
interface
uses SysUtils,Classes,Controls,QGraphics, {$ifdef ver150} DesignIntf, DesignEditors,{$else} DsgnIntf,{$endif}EButton;
type TEColor = class(TColorProperty) public procedure Edit; override; end;
procedure Register;
implementation
procedure Register; begin RegisterComponents('RComponents', [TEButton]); RegisterPropertyEditor(TypeInfo(TColor), TEButton, 'Color', TRColor); end;
procedure TColorProperty.Edit; var ColorDialog: TColorDialog; begin ColorDialog := TColorDialog.Create(Application); try ColorDialog.Color := GetOrdValue; if ColorDialog.Execute then SetOrdValue(ColorDialog.Color);
finally ColorDialog.Free; end; end;
end. |
Danke für die Mühe...
Gruss Cherry