📄 main.cpp
字号:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "main.h"
#include "NewTable.h"
#include "Splite.h"
#include "Border.h"
#include "Color.h"
#include "Diagonal.h"
#include "PageSetup.h"
#include "About.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "CNReport"
#pragma link "XPMenu"
#pragma resource "*.dfm"
TfrmMain *frmMain;
//---------------------------------------------------------------------------
__fastcall TfrmMain::TfrmMain(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::FormCreate(TObject *Sender)
{
// ModifyMenu(MainMenu1->Handle,1,MF_BYPOSITION | MF_POPUP|MF_HELP,(WORD)mHelp->Handle,"帮助-");
cbFont->Items->AddStrings(Screen->Fonts);
cbZoom->ItemIndex = cbZoom->Items->IndexOf("100");
ReportFile = "";
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::btOpenClick(TObject *Sender)
{
if(OpenDialog1->Execute())
{
ReportFile = OpenDialog1->FileName;
if( FileExists(TempFile) )
{
DeleteFile(TempFile);
}
CNReportControl1->LoadFromFile(OpenDialog1->FileName);
Caption = ReportFile;
if(CNReportControl1->Width > ScrollBox1->Width)
{
CNReportControl1->Left = 0;
}
else
{
CNReportControl1->Left = (ScrollBox1->Width - CNReportControl1->Width) /2;
}
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::cbZoomChange(TObject *Sender)
{
CNReportControl1->SetScale(cbZoom->Text.ToInt());
if(CNReportControl1->Width > ScrollBox1->Width)
{
CNReportControl1->Left = 0;
}
else
{
CNReportControl1->Left = (ScrollBox1->Width - CNReportControl1->Width) /2;
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::ToolButton24Click(TObject *Sender)
{
CNReportControl1->SaveToFile(TempFile);
CNReportRunTime1->ReportFile = TempFile;
CNReportRunTime1->EnableEdit = false;
CNReportRunTime1->PrintPreview(True);
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::btSaveClick(TObject *Sender)
{
if( ReportFile == "")
{
if(SaveDialog1->Execute())
{
ReportFile = SaveDialog1->FileName;
if( FileExists(TempFile) )
{
DeleteFile(TempFile);
}
CNReportControl1->SaveToFile(ReportFile);
}
}
else
{
CNReportControl1->SaveToFile(ReportFile);
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::SetSB(int Index, AnsiString Text)
{
//TODO: Add your source code here
SB->Panels->Items[Index]->Text = Text;
}
void __fastcall TfrmMain::CNReportControl1MouseMove(TObject *Sender,
TShiftState Shift, int X, int Y)
{
HDC hTempDC;
TPoint pt, ptOrg;
hTempDC = GetDC(0);
pt.y = abs(CNReportControl1->CellFont.lfHeight) *720 / GetDeviceCaps(hTempDC, LOGPIXELSY);
DPtoLP(hTempDC,&pt,1);
ptOrg.x = 0;
ptOrg.y = 0;
DPtoLP(hTempDC, &ptOrg, 1);
if(CNReportControl1->ReportScale == 100) SetSB(0,"");
SetSB(1,AnsiString(CNReportControl1->CellFont.lfFaceName) + " [" + IntToStr((pt.y-ptOrg.y) / 10) + "]");
SetSB(2,"X:" + IntToStr(X) + " Y:" + IntToStr(Y));
if( celldisp != NULL)
{
btItalic->Down = false;
btBold->Down = false;
btUnderline->Down = false;
if( celldisp->HorzAlign == 0) btLeft->Down = true;
if( celldisp->HorzAlign == 1) btCenter->Down = true;
if( celldisp->HorzAlign == 2) btRight->Down = true;
if( celldisp->VertAlign == 0) btTop->Down = true;
if( celldisp->VertAlign == 1) btMedium->Down = true;
if( celldisp->VertAlign == 2) btBottom->Down = true;
if( celldisp->LogFont.lfItalic == 1) btItalic->Down = true;
if( celldisp->LogFont.lfUnderline == 1) btUnderline->Down = true;
if( celldisp->LogFont.lfWeight == 700) btBold->Down = true;
for(int i = 0; i < cbFont->Items->Count; i++)
{
if( cbFont->Items->Strings[i] == celldisp->LogFont.lfFaceName)
{
cbFont->ItemIndex = i;
break;
}
}
hTempDC = GetDC(0);
pt.y = abs(celldisp->LogFont.lfHeight) * 720 / GetDeviceCaps(hTempDC, LOGPIXELSY);
DPtoLP(hTempDC, &pt, 1);
ptOrg.x = 0;
ptOrg.y = 0;
DPtoLP(hTempDC, &ptOrg, 1);
cbFontSize->Text = IntToStr((pt.y - ptOrg.y) / 10);
// SetSB(3,celldisp->CellText);
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::btLeftClick(TObject *Sender)
{
char h, v;
h = 3, v = 3;
if( btLeft->Down) h = 0;
if( btCenter->Down) h = 1;
if( btRight->Down) h = 2;
if( btTop->Down) v = 0;
if( btMedium->Down) v = 1;
if( btBottom->Down) v = 2;
CNReportControl1->SetCellAlign(h, v);
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::btNewTableClick(TObject *Sender)
{
if( frmNewTable->ShowModal() == IDOK)
{
CNReportControl1->NewTable(frmNewTable->Edit_Row->Text.ToInt(), frmNewTable->Edit_Col->Text.ToInt());
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::btAppendLineClick(TObject *Sender)
{
//增加一行
CNReportControl1->AddLine();
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::btInsertLineClick(TObject *Sender)
{
//插入一行
CNReportControl1->InsertLine();
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::btDeleteLineClick(TObject *Sender)
{
//删除一行
CNReportControl1->DeleteLine();
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::btAddCellClick(TObject *Sender)
{
//增加单元格
CNReportControl1->AddCell();
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::btInsertCellClick(TObject *Sender)
{
//插入单元格
CNReportControl1->InsertCell();
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::btDeleteCellClick(TObject *Sender)
{
//删除单元格
CNReportControl1->DeleteCell();
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::btCombineCellClick(TObject *Sender)
{
//合并单元格
CNReportControl1->CombineCell();
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::btVSplitCellClick(TObject *Sender)
{
//纵向拆分单元格
if( frmSplite->ShowModal() == IDOK)
{
CNReportControl1->VSplitCell(frmSplite->Edit_Col->Text.ToInt());
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::btSplitCellClick(TObject *Sender)
{
//横向拆分单元格
CNReportControl1->SplitCell();
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::btBorderClick(TObject *Sender)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -