Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   GUI-Design mit VCL / FireMonkey / Common Controls (https://www.delphipraxis.net/18-gui-design-mit-vcl-firemonkey-common-controls/)
-   -   Delphi Auf RichEdit zeichnen (https://www.delphipraxis.net/30895-auf-richedit-zeichnen.html)

F.W. 30. Sep 2004 21:08


Auf RichEdit zeichnen
 
Halli hallo!

Ich habe seit 2 Tagen die Vostellung auf ein RichEdit zu zeichnen, hatte aber bis eben keine Zeit. Aber es hat auch nicht funktioniert!

Delphi-Quellcode:
  TREEx = class(TRichEdit)
  private
    procedure WMPaint(var Msg: TWMPaint); message WM_Paint;
  end;

    { ... }

procedure TREEx.WMPaint(var Msg: TWMPaint);
var
 C: TCanvas;
begin
 C := TCanvas.Create;
 try
   C.Handle := Msg.DC;
   C.Ellipse(10, 10, 100, 100);
 finally
   C.Free;
 end;
end;
Aber wenn's zum zeichnen in der WMPaint Methode kommt, bekomme ich ein Fehler, dass ich auf der Leinwand nicht zeichnen darf!
Welche Wege gibt es noch, um auf ein RichEdit zu zeichnen?

Danke schonmal!

mischerr 30. Sep 2004 22:04

Re: Auf RichEdit zeichnen
 
Also hier hatte ich bei sowas mal mit:
Code:
with TCanvas.Create do begin
     Handle:= GetDC(self.Handle);
     MoveTo(100, 100);
     LineTo(150, 150);
     Free;
end;
Erfolg...

franz 30. Sep 2004 22:38

Re: Auf RichEdit zeichnen
 
Hi,
du kannst aber auch eine neue RichEdit Komponente erstellen.

Delphi-Quellcode:
type
  TCanvasRichEdit = class(TRichEdit)
  private
    FCanvas: TControlCanvas;
    function GetCanvas: TCanvas;
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;

    property Canvas: TCanvas
      read GetCanvas;
  end;

constructor TCanvasRichEdit.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  ScrollBars := ssBoth;
  FCanvas := TControlCanvas.Create;
  FCanvas.Control := Self;
end;

destructor TCanvasRichEdit.Destroy;
begin
  FCanvas.Free;
  inherited Destroy;
end;

function TCanvasRichEdit.GetCanvas: TCanvas;
begin
  Result := FCanvas;
end;
Anschließend kann die Eigenschaft Canvas der neue Kompo zum Zeichnen verwendet werden.

Nur mal so schnell - ungetestet.

F.W. 1. Okt 2004 16:22

Re: Auf RichEdit zeichnen
 
Danke! Hat geklappt!


Alle Zeitangaben in WEZ +1. Es ist jetzt 12:16 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