📄 printing.cpp
字号:
//---------------------------------------------------------------------------
#include <vcl.h>
#include <Printers.hpp>
#include <math.h>
#pragma hdrstop
#include "printing.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "ChartfxLib_TLB"
#pragma link "Dialogs"
#pragma link "OleCtrls"
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::RadioButton1Click(TObject *Sender)
{
IToolbarItemDisp pToolItem;
ChartFX1->Printer->set_Orientation(ORIENTATION_PORTRAIT);
ChartFX1->ToolBarObj->get_Item(1,&pToolItem);
pToolItem.CommandID = CFX_ID_PRINT;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::RadioButton2Click(TObject *Sender)
{
IToolbarItemDisp pToolItem;
ChartFX1->Printer->set_Orientation(ORIENTATION_LANDSCAPE);
ChartFX1->ToolBarObj->get_Item(1,&pToolItem);
pToolItem.CommandID = CFX_ID_PRINT;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::RadioButton3Click(TObject *Sender)
{
IToolbarItemDisp pToolItem;
ChartFX1->Printer->set_Orientation(ORIENTATION_DEFAULT);
ChartFX1->ToolBarObj->get_Item(1,&pToolItem);
pToolItem.CommandID = CFX_ID_DLGPRINT; // Show printer setup dialog before printer
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
ChartFX1->ShowDialog(CDIALOG_PAGESETUP, 0);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
char sDevice[255],sDriver[255],sPort[255];
THandle devMode;
if (RadioButton3->Checked) { // prompt user
if (PrinterSetupDialog1->Execute()) {
Printer()->GetPrinter(sDevice,sDriver,sPort,devMode);
ChartFX1->Printer->set_PrinterDriver(StringToOleStr(String(sDevice)+String(" ,")+String(sDriver)+String(" ,")+String(sPort)));
}
}
ChartFX1->PrintIt(0, 0); // Print
ChartFX1->Printer->set_PrinterDriver(NULL); // Restore
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button3Click(TObject *Sender)
{
long lLastPoint,nTotPages,nTotPoints;
short nPage;
BOOL bQuit;
String s,sPage,sTot;
char sDevice[255],sDriver[255],sPort[255];
THandle devMode;
if (RadioButton3->Checked) { // prompt user
if (PrinterSetupDialog1->Execute()) {
Printer()->GetPrinter(sDevice,sDriver,sPort,devMode);
ChartFX1->Printer->set_PrinterDriver(StringToOleStr(String(sDevice)+String(" ,")+String(sDriver)+String(" ,")+String(sPort)));
}
}
// Print one page at a time
bQuit = FALSE;
nPage = 1;
nTotPoints = ChartFX1->NValues;
nTotPages = -1;
while (!bQuit) {
lLastPoint = ChartFX1->PrintIt(nPage, nPage); // Print one page at a time
if (lLastPoint && (lLastPoint < nTotPoints)) { // Is there more ?
if (nTotPages < 0)
nTotPages = (int) ceil(((double) nTotPoints) / lLastPoint); // Calculate total
sTot = nTotPages;
sPage = nPage;
s = "Page " + sPage + " of " + sTot + " Done." + "\012 Another Page ?";
if (Application->MessageBox(s.c_str(),"Sample ...",MB_YESNO) != IDYES)
bQuit = TRUE;
nPage++; // Next page
} else
bQuit = TRUE;
}
ChartFX1->Printer->set_PrinterDriver(NULL); // Restore
}
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -