Einzelnen Beitrag anzeigen

Rumpi

Registriert seit: 26. Aug 2003
Ort: Berlin
72 Beiträge
 
#9

Re: Komponente zeichnet sich nicht neu, bei Font Änderung

  Alt 1. Dez 2003, 14:13
Das geht,

habs ausprobiert.
Du musst auch mit invalidate anstelle von paint arbeiten.

Delphi-Quellcode:
unit StatusScroll;

interface

uses
  SysUtils, Classes, Controls, Graphics, Messages;

type
  TStatusScroll = class(TGraphicControl)
  private
    { Private-Deklarationen }
    FLines: TStringList;
    FRowCount: Integer;
    FAlignment: TAlignment;
    procedure SetLines(const Value: TStringList);
    procedure SetAlignment(const Value: TAlignment);
    procedure CMFontChanged(var Message: TMessage); message CM_FONTCHANGED;
  protected
    { Protected-Deklarationen }
        procedure Paint; override;
  public
    { Public-Deklarationen }
    constructor Create(AOwner : TComponent); override;
    destructor destroy; override;

  published
   { Published-Deklarationen }
    property Lines : TStringList read FLines write SetLines;
    property RowCount : Integer read FRowCount;
    property Alignment : TAlignment read FAlignment write SetAlignment;
    property Font;
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('Beispiele', [TStatusScroll]);
end;

{ TStatusScroll } 

constructor TStatusScroll.Create(AOwner: TComponent);
begin
  inherited;
  FLines := TStringList.Create;
end;

destructor TStatusScroll.destroy;
begin
  FreeAndNIL(FLines);
  inherited;
end;

procedure TStatusScroll.Paint;
var FTextHeight, FTextWidth, t : integer;
    bmp : TBitmap;
begin
  inherited;
  with canvas do
  begin
    Font.Assign( Self.Font );
    Brush.Style := BSClear;
    Pen.Color := Font.Color;
    FTextHeight := TextHeight('Ü,');
    FRowCount := trunc( height / ( FTextHeight + 4) );
    For t:= 0 to FRowCount-1 do
    begin
      if ( t <= Flines.Count -1 ) then
      begin
        FTextwidth := TextWidth(Flines.strings[t]);
        case FAlignment of
          taLeftJustify: TextOut(2,( t * ( FTextHeight + 4 ) + 2 ),Flines.Strings[t]);
          taRightJustify: TextOut(width - FTextwidth -2,( t * ( FTextHeight + 4 ) + 2 ),Flines.Strings[t]);
          taCenter: TextOut(trunc ( (width - FTextwidth -4) /2 ),( t * ( FTextHeight + 4 ) + 2 ),Flines.Strings[t]);
        end;
      end;
    end;
  end;
end;

procedure TStatusScroll.SetAlignment(const Value: TAlignment);
begin
  if FAlignment <> Value then
  begin
    FAlignment := Value;
    Invalidate; // Paint;
  end;
end;

procedure TStatusScroll.SetLines(const Value: TStringList);
begin
  FLines.Assign(Value);
  Invalidate; // Paint;
end;

procedure TStatusScroll.CMFontChanged(var Message: TMessage);
begin
  inherited;
  Invalidate;
end;

end.
mfg Rumpi
  Mit Zitat antworten Zitat