unit Unit1;

interface

uses
  Windows, Messages, SysUtils, QPrinters,Variants, Classes, Graphics, Controls, Forms,
  Dialogs, TeeSurfa, TeEngine, TeeMapSeries, Chart, TeeProcs,
  TeePreviewPanel, ExtCtrls, StdCtrls, Series, TeeSmith, GanttCh, TeeEdit;

type
  TForm1 = class(TForm)
    Panel1: TPanel;
    Panel2: TPanel;
    TeePreviewPanel1: TTeePreviewPanel;
    Chart1: TChart;
    Chart2: TChart;
    Chart3: TChart;
    Chart4: TChart;
    Series1: TMapSeries;
    Series2: TSurfaceSeries;
    Series3: TGanttSeries;
    Series4: TColorGridSeries;
    Button1: TButton;
    Panel3: TPanel;
    CheckBox1: TCheckBox;
    CheckBox2: TCheckBox;
    CheckBox3: TCheckBox;
    CheckBox4: TCheckBox;
    Button2: TButton;
    ChartPreviewer1: TChartPreviewer;
    PageSetupDialog1: TPageSetupDialog;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure CheckBox1Click(Sender: TObject);
    procedure CheckBox2Click(Sender: TObject);
    procedure CheckBox3Click(Sender: TObject);
    procedure CheckBox4Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);

  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  newIndex,curIndex:Integer;
implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
Series1.FillSampleValues(15);
Series2.FillSampleValues(20);
Series3.FillSampleValues(5);
Series4.FillSampleValues(10);
TeePreviewPanel1.PrintMargins := Rect(10,10,40,60);

end;

procedure TForm1.Button1Click(Sender: TObject);
begin
Close;
end;

procedure TForm1.CheckBox1Click(Sender: TObject);
var
i:integer;
begin //显示第一个Chart
if CheckBox1.Checked then
  begin
//  Chart1.PrintMargins.Left := 10;
//  Chart1.PrintMargins.Top := 10;
//  Chart1.PrintMargins.Right := 40;
//  Chart1.PrintMargins.Bottom := 60;
//   := Rect(10,10,40,60);
//  PageSetupDialog1.MarginTop := 10;
//  PageSetupDialog1.MarginRight := 40;
//  PageSetupDialog1.MarginBottom := 60;

//  TeePreviewPanel1.PrintMargins := Rect(10,10,40,60);
    TeePreviewPanel1.Panels.Add(Chart1);
    Chart1.PrintMargins := Rect(10,10,40,60);
    Chart1.Refresh;
  i :=  TeePreviewPanel1.Panels.IndexOf(Chart1);
  if  i> 0 then
      TeePreviewPanel1.Panels.Move(i-1,i);
  TeePreviewPanel1.Refresh;
  end
  else
  begin
  TeePreviewPanel1.Panels.Remove(Chart1);
  TeePreviewPanel1.Refresh;
  end;
end;

procedure TForm1.CheckBox2Click(Sender: TObject);
var
i:integer;
begin  //显示第二个Chart
if CheckBox2.Checked then
  begin
  TeePreviewPanel1.Panels.Add(Chart2);
  i := TeePreviewPanel1.Panels.IndexOf(Chart2);
  if i>0 then
    TeePreviewPanel1.Panels.Move(i-1,i);
  TeePreviewPanel1.Refresh;
  end
  else
  begin
   TeePreviewPanel1.Panels.Remove(Chart2);
  TeePreviewPanel1.Refresh;
  end;
end;

procedure TForm1.CheckBox3Click(Sender: TObject);
var
i:Integer;
begin  //显示第三个Chart
if CheckBox3.Checked then
  begin
  TeePreviewPanel1.Panels.Add(Chart3);
  i := TeePreviewPanel1.Panels.IndexOf(Chart3);
  if i>0 then
    TeePreviewPanel1.Panels.Move(i-1,i);
  TeePreviewPanel1.Refresh;
  end
  else
  begin
   TeePreviewPanel1.Panels.Remove(Chart3);
  TeePreviewPanel1.Refresh;
  end;
end;

procedure TForm1.CheckBox4Click(Sender: TObject);
var
i:integer;
begin    //显示第四个Chart
if CheckBox4.Checked then
  begin
  TeePreviewPanel1.Panels.Add(Chart4);
  i := TeePreviewPanel1.Panels.IndexOf(Chart4);
  if  i>0 then
    TeePreviewPanel1.Panels.Move(i-1,i);
  TeePreviewPanel1.Refresh;
  end
  else
  begin
  TeePreviewPanel1.Panels.Remove(Chart4);
  TeePreviewPanel1.Refresh;
  end;
end;


procedure TForm1.Button2Click(Sender: TObject);
begin
//Chart1.PrintMargins := Rect(10,10,40,60);
{
PageSetupDialog1.MarginLeft := 10;
PageSetupDialog1.MarginTop := 10;
PageSetupDialog1.MarginRight := 40;
PageSetupDialog1.MarginBottom := 60;
ChartPreviewer1.Execute;
}
TeePreviewPanel1.Print;
end;

end.
