Einzelnen Beitrag anzeigen

Benutzerbild von CreativeMD
CreativeMD

Registriert seit: 11. Okt 2011
127 Beiträge
 
Delphi XE2 Architect
 
#24

AW: Fehler beim Parent setzen eines Labels

  Alt 9. Jul 2012, 22:00
ok
Ich hab mir eine eigene Komponente geschriebn, doch
kann ich in der Komponente eine Scrollbar benutzten, auf jedenfall
wird sie irgendwie nicht angezeigt.

Delphi-Quellcode:
unit ChatEdit;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
  System.Classes, Vcl.Graphics, Vcl.StdCtrls, Winapi.CommCtrl ,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Contnrs, Vcl.Themes;

type
  TChatEdit = class(TCustomControl)
  private
    FFont: TFont;
    FLines: TStringList;
    Special_Objects: TObjectList;
    FScrollbar : TScrollBar;

    procedure setLines(Value: TStringList);
    procedure setFont(Value: TFont);
    procedure setScrollbar(Value : TScrollBar);
    procedure onScrollbarChange(Sender: TObject);
    { Private-Deklarationen }
  protected

    procedure Paint; override;
    { Protected-Deklarationen }
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;

    procedure Clear;
    procedure AddLine(Text: String);
    function Count: Integer;


    { Public-Deklarationen }
  published
    property OnClick;
    property OnMouseMove;

    property Font: TFont read FFont write setFont;
    property Lines: TStringList read FLines write setLines;
    property Scrollbar : TScrollBar read FScrollbar write setScrollbar;
    { Published-Deklarationen }
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('Chat', [TChatEdit]);
end;

constructor TChatEdit.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  FLines := TStringList.Create;
  FFont := TFont.Create;
  Special_Objects := TObjectList.Create;

  FScrollbar := TScrollBar.Create(self);
  FScrollbar.Kind := sbVertical;

  FScrollbar.OnChange := onScrollbarChange;


  FScrollbar.Top := 0;

  FScrollbar.Width := 20;

  

  FLines.Add(Self.GetNamePath);
end;

destructor TChatEdit.Destroy;
begin
  FFont.Destroy;
  Special_Objects.Free;
  FLines.Free;
  inherited Destroy;
end;

procedure TChatEdit.setFont(Value : TFont);
begin
FFont.Assign(Value);
Canvas.Font.Assign(FFont);
Paint;
end;

procedure TChatEdit.setLines(Value: TStringList);
begin
FLines.Assign(Value);
  Paint;
end;

procedure TChatEdit.setScrollbar(Value: TScrollBar);
begin
FScrollbar.Assign(Value);
Paint;
end;

procedure TChatEdit.Paint;
var
  zahl, height: Integer;
begin

  inherited;

  height := Canvas.TextHeight('h');
  for zahl := 0 to FLines.Count - 1 do
  begin
      Canvas.TextOut(0, zahl * height - FScrollbar.Position, FLines[zahl]);
  end;

  if zahl * height > Self.Height then
  begin

    FScrollbar.Max := zahl * height;
    FScrollbar.PageSize := zahl * height;


    FScrollbar.Enabled := true;
  end
  else
  begin
    FScrollbar.Enabled := false;
  end;

  FScrollbar.Left := Self.Width - FScrollbar.Width;
  FScrollbar.Height := Self.Height;
end;

procedure TChatEdit.onScrollbarChange(Sender: TObject);
begin
  Paint;
end;

function TChatEdit.Count: Integer;
begin
  Result := FLines.Count;
end;



procedure TChatEdit.Clear;
begin
  FLines.Clear;
end;

procedure TChatEdit.AddLine(Text: string);
begin
  FLines.Add(Text);
end;

end.
  Mit Zitat antworten Zitat