怎么将象素单位转换成毫米单位?
求公式?
求公式?
解决方案 »
- cxgridTableView关于ButtonEdit的问题
- update语句插入子查询出错
- 用ClientSocket怎样才能发送一个数字
- 如何拖动 listview 的行到想要的位置???????????急!!!!!!
- 急急急!!如何在fastreport中预览显示出数据库中的jpg图片字段?????????????????
- 三层数据库应用中出现访问拒绝的错误?
- 到底错再哪了啊?
- 怎么样调整一个form窗口的formstate属性?
- 开发基于广域网的程序,怎样开发,我是小菜,多多指教
- 讨教:报表里的问题。谢谢!!!
- delphi调用C++的动态连接库的问题
- 一个简单的字符串操作.帮忙看看!
function HPointsPerInch(Canvas: TCanvas): Integer; overload;
begin
Result := GetDeviceCaps(Canvas.Handle, LOGPIXELSX);
end;//取得纵向方向每英寸Canvas的点数
function VPointsPerInch(Canvas: TCanvas): Integer; overload;
begin
Result := GetDeviceCaps(Canvas.Handle, LOGPIXELSY)
end;//取得纵向方向每英寸打印机的光栅数
function VPointsPerInch: Integer; overload;
begin
Result := GetDeviceCaps(Printer.Handle, LOGPIXELSY)
end;//取得水平方向每英寸打印机的点数
function HPointsPerInch: Integer; overload;
begin
Result := GetDeviceCaps(Printer.Handle, LOGPIXELSX);
end;//横向点单位转换为毫米单位
function XPointToMm(Pos: Integer): Extended;
begin
Result := Pos*25.4/HPointsPerInch;
end;//纵向点单位转换为毫米单位
function YPointToMm(Pos: Integer): Extended;
begin
Result := Pos*25.4/VPointsPerInch;
end;
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, Printers, StdCtrls, DBCtrls, Mask, ComCtrls, Grids, DBGrids,
Chart;type
TPPanel = class(TPanel)
private
{ Private declarations }
SX,SY:Real;
FShowBorder:Boolean; FXOffset:Integer;
FYOffset:Integer; PreviewForm:TForm;
protected
{ Protected declarations }
public
{ Public declarations }
Constructor Create(AOwner:TComponent); Override;
Procedure PrintToCanvas(ACanvas:TCanvas); Procedure WhenKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
Procedure WhenFormPaint(Sender: TObject);
Procedure WhenFormClose(Sender: TObject; var Action: TCloseAction);
published
{ Published declarations }
Function Print(Preview:Boolean):Boolean;
Procedure About; Property ShowBorder:Boolean Read FShowBorder Write FShowBorder;
Property XOffset:Integer Read FXOffset Write FXOffset;
Property YOffset:Integer Read FYOffset Write FYOffset;
end;procedure Register;implementation//注册组件
procedure Register;
begin
RegisterComponents('Standard', [TPPanel]);
end;Constructor TPPanel.Create(AOwner:TComponent);
Begin
Inherited; FXOffset:=0;
FYOffset:=0;
End;//关于组件
Procedure TPPanel.About;
Begin
Application.MessageBox('PPanel 作者:彭富章 2000.03','关于 PPanel',MB_OK+MB_ICONINFORMATION);
End;//打印预览窗口键盘按下
Procedure TPPanel.WhenKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
Begin
If Key=VK_Return Then
Begin
Self.Print(False);
If Sender Is TForm Then
TForm(Sender).ModalResult:=mrOK;
End
Else If Key=VK_ESCAPE Then
PreViewForm.Close;
End;//窗口刷新
Procedure TPPanel.WhenFormPaint(Sender: TObject);
Begin
PrintToCanvas(PreviewForm.Canvas);
End;//窗口关闭
Procedure TPPanel.WhenFormClose(Sender: TObject; var Action: TCloseAction);
Begin
Action:=caFree;
End;//打印
Function TPPanel.Print(Preview:Boolean):Boolean;
Begin
Result:=False;
If Preview Then
Begin
SX:=1.0;
SY:=1.0; PreViewForm:=TForm.Create(Application);
PreViewForm.Caption:='打印预览 按[Enter]打印 按[Esc] 关闭';
PreViewForm.BorderStyle:=bsDialog;
PreViewForm.ClientWidth:=self.Width;
PreViewForm.ClientHeight:=self.Height;
PreViewForm.Color:=clWhite;
PreviewForm.Position:=poScreenCenter; PreviewForm.OnKeyDown:=WhenKeyDown;
PreviewForm.OnPaint:=WhenFormPaint;
PreviewForm.OnClose:=WhenFormClose; If PreViewForm.ShowModal=mrOK Then
Result:=True;
End
Else
Begin
SX:=GetDeviceCaps(Printer.Handle,logPixelsX)/Screen.PixelsPerInch;
SY:=GetDeviceCaps(Printer.Handle,logPixelsY)/Screen.PixelsPerInch; Printer.BeginDoc;
Printer.Title:='Doc printed by PrintPanel '+FormatDateTime('YYYY-MM-DD HH:MM:SS',Now);
PrintToCanvas(Printer.Canvas);
Printer.EndDoc; Result:=True;
End;
End;//绘制到指定画布
Procedure TPPanel.PrintToCanvas(ACanvas:TCanvas);
Var NowPage:Integer;
I,N:Integer;
AObj:TControl;
ARect:TRect;
PX,PY:Integer;
Stemp:String; WidthArray:Array[1..24] of Integer;
ValueArray:Array[1..24] Of String;
ColumnCount,X,Y,NowX,NowY:Integer; NowRow:Integer;
Begin
NowPage:=1; Try
ACanvas.Lock; With ACanvas Do
For I:=0 To ControlCount-1 Do
If Controls[I].Visible Then
Begin
AObj:=Controls[I];
ARect:=AObj.BoundsRect; ARect.Left:=ARect.Left+FXOffset;
ARect.Top:=ARect.Top+FYOffset;
ARect.Right:=ARect.Right+FXOffset;
ARect.Bottom:=ARect.Bottom+FYOffset; PX:=Round((ARect.Left+4)*SX);
PY:=Round((ARect.Top+2)*SY); ARect.Left:=Round(ARect.Left*SX);
ARect.Top:=Round(ARect.Top*SY);
ARect.Right:=Round(ARect.Right*SX);
ARect.Bottom:=Round(ARect.Bottom*SY); Font:=self.Font; If (FShowBorder ) Then //OR (AObj Is TStringGrid)
If ((AObj Is TEdit) OR (AObj Is TDBEdit) OR (AObj Is TMaskEdit) OR (AObj Is TDateTimePicker) OR (AObj Is TComboBox)
OR (AObj Is TDbComboBox) OR (AObj Is TMemo) OR (AObj Is TDBmemo) OR (AObj Is TDBGrid) OR (AObj Is TStringGrid)) Then
Begin
Pen.Width:=1;
MoveTo(ARect.Left,ARect.Top);
LineTo(ARect.Right,ARect.Top);
LineTo(ARect.Right,ARect.Bottom);
LineTo(ARect.Left,ARect.Bottom);
LineTo(ARect.Left,ARect.Top);
End;.
ScaleX,ScaleY:Integer;
MapRect:TRect;
begin
//设置像素点放大系数
ScaleX:=GetDeviceCaps(Printer.Handle,LogPixelsX) div PixelsPerInch;
ScaleY:=GetDeviceCaps(Printer.Handle,LogPixelsY) div PixelsPerInch; MapRect:=Rect(0, 0, Image1.Picture.Width * ScaleX , Image1.Picture.Height * ScaleY); // * ScaleX * ScaleY
//设置位图在打印机上的输出区域
Printer.BeginDoc; //开始打印作业
Printer.Canvas.StretchDraw(MapRect,Image1.Picture.Graphic);//输出位图
Printer.EndDoc; //结束打印作业