怎样做文本的打印预览?(100分)

  • 主题发起人 主题发起人 tby123456789
  • 开始时间 开始时间
T

tby123456789

Unregistered / Unconfirmed
GUEST, unregistred user!
怎样做文本的打印预览?
 
用Canvas自己画吧
 
RichEdit可以画到打印机画布上,同样,也可以画到屏幕画布上。

下面示例可以将RichEdit的内容输出到一个Image中
uses RichEdit;

procedure TForm1.Button1Click(Sender: TObject);
var
Range: TFormatRange;
LastChar, MaxLen, LogX, LogY: Integer;
begin
FillChar(Range, SizeOf(TFormatRange), 0);
with Image1, Range do
begin
LogX := GetDeviceCaps(Canvas.Handle, LOGPIXELSX);
LogY := GetDeviceCaps(Canvas.Handle, LOGPIXELSY);
hdc := Canvas.Handle;
hdcTarget := hdc;
rc.right := Image1.ClientWidth * 1440 div LogX;
rc.bottom := Image1.ClientHeight * 1440 div LogY;
rcPage := rc;
LastChar := 0;
MaxLen := GetTextLen;
chrg.cpMax := -1;
repeat
chrg.cpMin := LastChar;
LastChar := SendMessage(RichEdit1.Handle, EM_FORMATRANGE, 1,
Longint(@Range));
until (LastChar >= MaxLen) or (LastChar = -1);
end;
SendMessage(RichEdit1.Handle, EM_FORMATRANGE, 0, 0);
Image1.Refresh;
end;

 
后退
顶部