📄 ch17.htm
字号:
{
if (PrintDialog1->Execute())
{
SendToPrinter();
}
}
void __fastcall TForm1::Open1Click(TObject *Sender)
{
if
(OpenDialog1->Execute())
{
Memo1->Lines->LoadFromFile(OpenDialog1->FileName);
void __fastcall TForm1::ShapeForm1Click(TObject *Sender)
{
PaintBoxForm->ShowModal();
}
void __fastcall TForm1::BitmapForm1Click(TObject
*Sender)
{
PrintBitmapForm->ShowModal();
}
</FONT></PRE>
<H3 ALIGN="CENTER"><FONT COLOR="#0066FF"></FONT></H3>
<P><A NAME="Heading27"></A><FONT COLOR="#000077"><B>Listing 17.3. The header for
the PaintBoxPrint module.</B></FONT></P>
<PRE><FONT COLOR="#0066FF">///////////////////////////////////////
// File: PaintBoxPrint.h
// Project: PrintText
// Copyright (c) 1997 by Charlie Calvert
//
#ifndef PaintBoxPrintH
#define PaintBoxPrintH
#include <vcl\Classes.hpp>
#include <vcl\Controls.hpp>
#include <vcl\StdCtrls.hpp>
#include <vcl\Forms.hpp>
#include <vcl\ExtCtrls.hpp>
#include <vcl\Buttons.hpp>
#include <vcl\Dialogs.hpp>
class TPaintBoxForm : public TForm
{
__published:
TPaintBox *PaintBox1;
TBitBtn *PrintPictureBtn;
TBitBtn *ShowPictureBtn;
TPrintDialog *PrintDialog1;
void __fastcall PrintPictureBtnClick(TObject *Sender);
private:
void __fastcall ShowData(TCanvas *Canvas);
void
SendToPrinter();
public:
__fastcall TPaintBoxForm(TComponent* Owner);
};
extern TPaintBoxForm *PaintBoxForm;
#endif
</FONT></PRE>
<P><A NAME="Heading28"></A><FONT COLOR="#000077"><B>Listing 17.4. The main module
for the PaintBoxPrint
module.</B></FONT></P>
<PRE><FONT COLOR="#0066FF">///////////////////////////////////////
// File: PaintBoxPrint.cpp
// Project: PrintText
// Copyright (c) 1997 by Charlie Calvert
//
#include <vcl\vcl.h>
#include <vcl\printers.hpp>
#pragma hdrstop
#include "PaintBoxPrint.h"
#pragma resource "*.dfm"
TPaintBoxForm *PaintBoxForm;
__fastcall TPaintBoxForm::TPaintBoxForm(TComponent* Owner)
: TForm(Owner)
{
}
void __fastcall TPaintBoxForm::ShowData(TCanvas
*Canvas)
{
Canvas->Brush->Color = clBlue;
Canvas->Pen->Color = clYellow;
Canvas->Rectangle(0, 0, PaintBox1->Width, PaintBox1->Height);
Canvas->Font->Color = clYellow;
Canvas->TextOut(5, 5, "Hi");
Canvas->Brush->Color = clPurple;
Canvas->Ellipse(25, 25, 150, 150);
}
void TPaintBoxForm::SendToPrinter()
{
if (PrintDialog1->Execute())
{
TPrinter *APrinter = Printer();
APrinter->BeginDoc();
ShowData(APrinter->Canvas);
APrinter->EndDoc();
}
}
void __fastcall TPaintBoxForm::PrintPictureBtnClick(TObject *Sender)
{
switch(dynamic_cast<TButton *>(Sender)->Tag)
{
case 0:
{
SendToPrinter();
break;
}
case 1:
{
ShowData(PaintBox1->Canvas);
break;
}
}
</FONT></PRE>
<PRE><FONT COLOR="#0066FF">}
</FONT></PRE>
<H3 ALIGN="CENTER"><FONT COLOR="#0066FF"></FONT></H3>
<P><A NAME="Heading29"></A><FONT
COLOR="#000077"><B>Listing 17.5. The header for
the PrintBitmap module.</B></FONT></P>
<PRE><FONT COLOR="#0066FF">///////////////////////////////////////
// File: PrintBmp.h
// Project: PrintText
// Copyright (c) 1997 by Charlie Calvert
//
#ifndef PrintBmp1H
#define PrintBmp1H
#include <vcl\Classes.hpp>
#include <vcl\Controls.hpp>
#include <vcl\StdCtrls.hpp>
#include <vcl\Forms.hpp>
#include <vcl\ExtCtrls.hpp>
#include <vcl\Menus.hpp>
#include
<vcl\Dialogs.hpp>
class TPrintBitmapForm : public TForm
{
__published:
TImage *Image1;
TMainMenu *MainMenu1;
TMenuItem *File1;
TMenuItem *Open1;
TMenuItem *Print1;
TMenuItem *N1;
TMenuItem *Exit1;
TOpenDialog
*OpenDialog1;
TPrintDialog *PrintDialog1;
TMenuItem *Options1;
TMenuItem *Stretch1;
void __fastcall Open1Click(TObject *Sender);
void __fastcall Print1Click(TObject *Sender);
void __fastcall Exit1Click(TObject *Sender);
void
__fastcall Stretch1Click(TObject *Sender);
private:
public:
__fastcall TPrintBitmapForm(TComponent* Owner);
};
extern TPrintBitmapForm *PrintBitmapForm;
#endif
</FONT></PRE>
<H3 ALIGN="CENTER"><FONT COLOR="#0066FF"></FONT></H3>
<P><A
NAME="Heading30"></A><FONT COLOR="#000077"><B>Listing 17.6. The main form for
the PrintBitmap module.</B></FONT></P>
<PRE><FONT COLOR="#0066FF">///////////////////////////////////////
// File: PrintBmp.cpp
// Project: PrintText
// Copyright (c)
1997 by Charlie Calvert
//
#include <vcl\vcl.h>
#include <vcl\printers.hpp>
#pragma hdrstop
#include "PrintBmp1.h"
#pragma resource "*.dfm"
TPrintBitmapForm *PrintBitmapForm;
__fastcall
TPrintBitmapForm::TPrintBitmapForm(TComponent* Owner)
: TForm(Owner)
{
}
void __fastcall TPrintBitmapForm::Open1Click(TObject *Sender)
{
if (OpenDialog1->Execute())
{
Image1->Picture->LoadFromFile(OpenDialog1->FileName);
}
}
void __fastcall TPrintBitmapForm::Print1Click(TObject *Sender)
{
if (PrintDialog1->Execute())
{
TPrinter *APrinter = Printer();
APrinter->BeginDoc();
APrinter->Canvas->Draw(1, 1, Image1->Picture->Bitmap);
APrinter->EndDoc();
}
}
void __fastcall TPrintBitmapForm::Exit1Click(TObject *Sender)
{
Close();
}
void __fastcall TPrintBitmapForm::Stretch1Click(TObject *Sender)
{
Stretch1->Checked = !Stretch1->Checked;
Image1->Stretch = Stretch1->Checked;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -