unit2.cpp
来自「C++ Builder 6 编程实例教程-北京希望电子出版社出版」· C++ 代码 · 共 84 行
CPP
84 行
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit2.h"
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm2 *Form2;
//---------------------------------------------------------------------------
__fastcall TForm2::TForm2(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm2::FormCreate(TObject *Sender)
{
int i;
int j;
//定义变量
Form2->StringGrid1->ColCount=Form1->VtChart1->ColumnCount+1;
Form2->StringGrid1->RowCount=Form1->VtChart1->RowCount+1;
//设置表格的大小
for (i=0;i<=Form1->VtChart1->ColumnCount;i++)
{
Form2->StringGrid1->Cells[i][0]=IntToStr(i);
}
for (j=0;j<=Form1->VtChart1->RowCount;j++)
{
Form2->StringGrid1->Cells[0][j]=IntToStr(j);
}
//设置表格的标题
for (i=1;i<=Form1->VtChart1->ColumnCount;i++)
{
for (j=1;j<=Form1->VtChart1->RowCount;j++)
{
Form1->VtChart1->Column=i;
Form1->VtChart1->Row=j;
Form2->StringGrid1->Cells[i][j]=Form1->VtChart1->Data;
//初始化表格中的数据
}
}
}
//---------------------------------------------------------------------------
void __fastcall TForm2::Button1Click(TObject *Sender)
{
int i;
int j;
//变量定义
for (i=1;i<=Form1->VtChart1->ColumnCount;i++)
{
for (j=1;j<=Form1->VtChart1->RowCount;j++)
{
Form1->VtChart1->Column=i;
Form1->VtChart1->Row=j;
Form1->VtChart1->Data=Form2->StringGrid1->Cells[i][j];
//以表格中的数据填充图表
}
}
Form1->Show();
Form2->Hide();
//显示主窗体
}
//---------------------------------------------------------------------------
void __fastcall TForm2::Button2Click(TObject *Sender)
{
Form1->Show();
Form2->Hide();
//显示主窗体
}
//---------------------------------------------------------------------------
void __fastcall TForm2::FormClose(TObject *Sender, TCloseAction &Action)
{
Form1->Show();
//显示主窗体
}
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?