Unit1.cpp
上传用户:lhxd_sz
上传日期:2014-10-02
资源大小:38814k
文件大小:2k
- //---------------------------------------------------------------------------
- #include <vcl.h>
- #include <printers.hpp>
- #pragma hdrstop
- #include "Unit1.h"
- //---------------------------------------------------------------------------
- #pragma package(smart_init)
- #pragma resource "*.dfm"
- TForm1 *Form1;
- //---------------------------------------------------------------------------
- __fastcall TForm1::TForm1(TComponent* Owner)
- : TForm(Owner)
- {
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button1Click(TObject *Sender)
- {
- TPrinter *prn;
- Graphics::TBitmap *bmp;
- int dpi,PageWidth,PageHeight;
- prn=Printer();
- dpi=GetDeviceCaps(Printer()->Handle,LOGPIXELSX);
- PageWidth=5;//预定义5英寸
- PageHeight=5;
- bmp = new Graphics::TBitmap();
- bmp->Width=PageWidth*dpi;
- bmp->Height=PageHeight*dpi;
- bmp->Canvas->Font->PixelsPerInch=dpi;
- bmp->Canvas->Rectangle(0.2*dpi,0.2*dpi,(5-0.2)*dpi,(5-0.2)*dpi);
- bmp->Canvas->Font->Size=12;
- bmp->Canvas->TextOut(0.3*dpi,0.3*dpi,"中华人民共和国");
- bmp->Canvas->TextOut(0.3*dpi,0.5*dpi,"全国人民代表大会");
- PaintBox1->Canvas->CopyRect(Rect(0,0,PaintBox1->Width,PaintBox1->Height),
- bmp->Canvas,Rect(0,0,bmp->Width,bmp->Height));
- if(Application->MessageBox("打印吗","提示",MB_YESNO)==IDYES)
- {
- prn->BeginDoc();
- prn->Canvas->StretchDraw(Rect(50,50,PageWidth*dpi,PageHeight*dpi),bmp);
- // Printer()->Canvas->TextOut(0.3*dpi,0.3*dpi,"中华人民共和国111");
- // Printer()->Canvas->CopyRect(Rect(50,50,PageWidth*dpi+50,PageHeight*dpi+50),
- // bmp->Canvas,Rect(0,0,bmp->Width,bmp->Height));
- prn->EndDoc();
- }
- delete bmp;
- }
- //---------------------------------------------------------------------------