AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Paintto Scrollbar?

Ein Thema von CreativeMD · begonnen am 12. Jul 2012 · letzter Beitrag vom 12. Jul 2012
Antwort Antwort
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
Benutzerbild von Bummi
Bummi

Registriert seit: 15. Jun 2010
Ort: Augsburg Bayern Süddeutschland
3.470 Beiträge
 
Delphi XE3 Enterprise
 
#2

AW: Paintto Scrollbar?

  Alt 12. Jul 2012, 13:34
Parent fehlt ...

Delphi-Quellcode:
  FScrollbar := TScrollBar.Create(self);
  FScrollbar.Parent := self;
Thomas Wassermann H₂♂
Das Problem steckt meistens zwischen den Ohren
DRY DRY KISS
H₂ (wenn bei meinen Snipplets nichts anderes angegeben ist Lizenz: WTFPL)
  Mit Zitat antworten Zitat
Benutzerbild von CreativeMD
CreativeMD

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

AW: Paintto Scrollbar?

  Alt 12. Jul 2012, 14:25
Vielen Vielen Dank,

Leichtsinnsfehler sind das schlimmste was einen passieren kann.
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 08:47 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz