Einzelnen Beitrag anzeigen

Benutzerbild von CreativeMD
CreativeMD

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

Paintto Scrollbar?

  Alt 12. Jul 2012, 13:09
Hi,

Ich will ein ChatSystem programmieren
http://www.delphipraxis.net/169086-f...-labels-3.html

nun habe ich es in eine Komponente geschrieben.

Wie schon im letzten Post vom anderen Thema beschrieben, wird die Scrollbar nicht angeteigt.
Kann ich dieses Problem nicht mit Paintto beheben.
Auf jedenfall funktioniert es irgendwie nicht.

Delphi-Quellcode:
FScrollbar.Paintto(Handle,0,0);
FScrollbar.Paintto(Canvas,0,0);
FScrollbar.Paintto(Canvas.Handle,0,0);
Es kompiliert zwar, aber bei der Anwendung kommt ein Fehlermeldung.

Wie kann ich das Problem lösen

Vielen Dank im voraus.

Code:
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