Recent Posts

Selamat datang di Coding Delphi Land Weblog kumpulan source code pemogram delphi

(Bukan maksud untuk menggurui tetapi marilah kita berbagi ilmu tuk perkembangan kemajuan teknologi kita

Senin, 16 November 2009

Rictedit To Canvas

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, jpeg, RichEdit, ComCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
bmp: TImage;
RichEdit1: TRichEdit;
procedure RichEditToCanvas(ARichEdit: ComCtrls.TRichEdit;
ACanvas: Graphics.TCanvas; APixelsPerInch: Integer);
procedure Button1Click(Sender: TObject);

private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.RichEditToCanvas(ARichEdit: ComCtrls.TRichEdit;
ACanvas: Graphics.TCanvas; APixelsPerInch: Integer);
var
Fmt: RichEdit.TFormatRange; // used by rich edit to format output
begin
with Fmt do
begin
hdc:= ACanvas.Handle;
hdcTarget:= hdc;
// rect needs to be specified in twips (1/1440 inch) as unit
rc := Classes.Rect(0,0,
ACanvas.ClipRect.Right * 1440 div APixelsPerInch,
ACanvas.ClipRect.Bottom * 1440 div APixelsPerInch
);
rcPage:= rc;
chrg.cpMin := 0;
chrg.cpMax := ARichEdit.GetTextLen;
end;
SetBkMode(ACanvas.Handle, Windows.TRANSPARENT);
ARichEdit.Perform(RichEdit.EM_FORMATRANGE,1,Integer(@Fmt));
// next call frees some cached data
ARichEdit.Perform(RichEdit.EM_FORMATRANGE,0,0);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
RichEditToCanvas(richedit1,bmp.Canvas ,4);
end;
end.

0 komentar:

Posting Komentar