ich habe mir ein Lineal gebastelt und nun stelle ich 2 Unterschiede gegenüber Delphi fest.
Code: Alles auswählen
with Canvas do begin
Brush.Color := clBtnFace;
FillRect(ClientRect);
end;
Code: Alles auswählen
MoveTo(x, Height - 9);
LineTo(x, Height);
Wie kann ich es erreichen, dass das Verhalten gleich wie bei Delphi ist?
Hier mal der Quelltext
Code: Alles auswählen
unit DiBoRuler;
interface
uses
SysUtils, Classes, Graphics, Controls;
type
TDiBoRuler = class(TGraphicControl)
private
FFont: TFont;
FLeftMargin,
CharWidth: integer;
procedure SetFont(Value: TFont);
procedure SetLeftMargin(Value: integer);
protected
procedure Paint; override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
property Align;
property Color;
property Enabled;
property Font;
property Height;
property PopupMenu;
property Visible;
property Width;
property EditFont: TFont read FFont write SetFont;
property LeftMargin: integer read FLeftMargin write SetLeftMargin;
end;
implementation
constructor TDiBoRuler.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
Align := alTop;
Color := clBtnFace;
Enabled := true;
Visible := true;
Height := 20;
Font.Name := 'Arial';
Font.Size := 8;
FFont := TFont.Create;
FFont.Name := 'Courier New';
FFont.Size := 10;
FLeftMargin := 3;
CharWidth := 8;
Parent := TWinControl(AOwner);
end;
destructor TDiBoRuler.Destroy;
begin
FFont.Free;
inherited;
end;
procedure TDiBoRuler.Paint;
var
x, p, h: integer;
s: string;
begin
p := 0; x := FLeftMargin;
with Canvas do begin
Brush.Color := Color;
FillRect(ClientRect);
repeat
h := 3;
if (p MOD 5) = 0 then inc(h, 3);
if (p MOD 10) = 0 then begin
s := IntToStr(p);
TextOut(x - TextWidth(s) SHR 1, 0, s);
inc(h, 3);
end;
MoveTo(x, Height - h);
LineTo(x, Height);
inc(x, CharWidth); inc(p);
until x >= Width;
end;
end;
procedure TDiBoRuler.SetFont(Value: TFont);
begin
FFont := Value;
Canvas.Font.Assign(Value);
CharWidth := Canvas.TextWidth('0');
Canvas.Font.Assign(Font);
Invalidate;
end;
procedure TDiBoRuler.SetLeftMargin(Value: integer);
begin
FLeftMargin := Value + 3;
Invalidate;
end;
end.
Code: Alles auswählen
Ruler := TDiBoRuler.Create(Self);
Ruler.EditFont.Assign(SynEdit1.Font);
Ruler.LeftMargin := SynEdit1.Gutter.Width;
Gruß