⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pagesetup.pas

📁 delphi制作表格的控件
💻 PAS
📖 第 1 页 / 共 2 页
字号:
begin
  with LbxTitleType, TEasyGrid(ParentGrid).EasyGridPageInfo.CommonPageInfo do
  begin
    case ItemIndex of
      0 : FTitle := FMainTitle;
      1 : FTitle := FTitle1;
      2 : FTitle := FTitle2;
      3 : FTitle := FTitle3;
      4 : FTitle := FTitle4;
      5 : FTitle := FTitle5;
      6 : FTitle := FTitle6;
    end;
    GetTitleProp;
  end;
end;

procedure TFormPageSetup.LbxTailTypeClick(Sender: TObject);

  procedure GetTailProp;
  begin
    with FTail do
    begin
      MemoTailContent.Clear;
      MemoTailContent.Lines.Add(Content);
      MemoTailContent.SelStart := 1;
      MemoTailContent.SelLength := 0;
      MemoTailContent.Font.Name := FontName;
      MemoTailContent.Font.Size := FontSize;
      MemoTailContent.Font.Style := FontStyle;
      MemoTailContent.Font.Color := FontColor;
      SEditTailDistance.Value := Round(Distance / ScreenPixelsPerMmY);
    end;
  end;

begin
  with LbxTailType, TEasyGrid(ParentGrid).EasyGridPageInfo.CommonPageInfo do
  begin
    case ItemIndex of
      0 : FTail := FTail1;
      1 : FTail := FTail2;
      2 : FTail := FTail3;
      3 : FTail := FTail4;
      4 : FTail := FTail5;
      5 : FTail := FTail6;
    end;
    GetTailProp;
  end;
end;

procedure TFormPageSetup.CbxHeaderTypeChange(Sender: TObject);
var
  Grid: TEasyGrid;
begin
  Grid := TEasyGrid(ParentGrid);
  with CbxHeaderType, Grid.EasyGridPageInfo.CommonPageInfo do
  begin
    case ItemIndex of
      0 : // 自定义页眉
        begin
          CbxHLineStyle.ItemIndex := Ord(HeaderLineStyle);
          ChkBoxHDoubleLine.Checked := HeaderDoubleLine;
          SEditHLineWidth.Value := HeaderLineWidth;
          EditHeader1.Text := Header1.Content;
          EditHeader2.Text := Header2.Content;
          EditHeader3.Text := Header3.Content;
        end;
      1 :
        begin
          CbxHLineStyle.ItemIndex := 0;
          ChkBoxHDoubleLine.Checked := True;
          SEditHLineWidth.Value := 1;
          EditHeader1.Text := '';
          EditHeader2.Text := '第 &P 页';
          EditHeader3.Text := '';
        end;
      2 :
        begin
          CbxHLineStyle.ItemIndex := 0;
          ChkBoxHDoubleLine.Checked := True;
          SEditHLineWidth.Value := 1;
          EditHeader1.Text := '';
          EditHeader2.Text := '第 &P 页, 共 &C 页';
          EditHeader3.Text := '';
        end;
      3 :
        begin
          CbxHLineStyle.ItemIndex := 0;
          ChkBoxHDoubleLine.Checked := True;
          SEditHLineWidth.Value := 1;
          EditHeader1.Text := '报表1';
          EditHeader2.Text := '&D';
          EditHeader3.Text := '第 &P 页';
        end;
      4 :
        begin
          CbxHLineStyle.ItemIndex := 0;
          ChkBoxHDoubleLine.Checked := True;
          SEditHLineWidth.Value := 1;
          EditHeader1.Text := '报表1';
          EditHeader2.Text := '&T';
          EditHeader3.Text := '第 &P 页';
        end;
    end;
    AssignEditProp(Header1, EditHeader1);
    AssignEditProp(Header2, EditHeader2);
    AssignEditProp(Header3, EditHeader3);
  end;
end;

procedure TFormPageSetup.CbxFooterTypeChange(Sender: TObject);
var
  Grid: TEasyGrid;
begin
  Grid := TEasyGrid(ParentGrid);
  with CbxFooterType, Grid.EasyGridPageInfo.CommonPageInfo do
  begin
    case ItemIndex of
      0 : // 自定义页脚
        with Grid.EasyGridPageInfo.CommonPageInfo do
        begin
          CbxFLineStyle.ItemIndex := Ord(FooterLineStyle);
          ChkBoxFDoubleLine.Checked := FooterDoubleLine;
          SEditFLineWidth.Value := FooterLineWidth;
          EditFooter1.Text := Footer1.Content;
          EditFooter2.Text := Footer2.Content;
          EditFooter3.Text := Footer3.Content;
        end;
      1 :
        begin
          CbxFLineStyle.ItemIndex := 0;
          ChkBoxFDoubleLine.Checked := True;
          SEditFLineWidth.Value := 1;
          EditFooter1.Text := '';
          EditFooter2.Text := '第 &P 页';
          EditFooter3.Text := '';
        end;
      2 :
        begin
          CbxFLineStyle.ItemIndex := 0;
          ChkBoxFDoubleLine.Checked := True;
          SEditFLineWidth.Value := 1;
          EditFooter1.Text := '';
          EditFooter2.Text := '第 &P 页, 共 &C 页';
          EditFooter3.Text := '';
        end;
      3 :
        begin
          CbxFLineStyle.ItemIndex := 0;
          ChkBoxFDoubleLine.Checked := True;
          SEditFLineWidth.Value := 1;
          EditFooter1.Text := '报表1';
          EditFooter2.Text := '&D';
          EditFooter3.Text := '第 &P 页';
        end;
      4 :
        begin
          CbxFLineStyle.ItemIndex := 0;
          ChkBoxFDoubleLine.Checked := True;
          SEditFLineWidth.Value := 1;
          EditFooter1.Text := '报表1';
          EditFooter2.Text := '&T';
          EditFooter3.Text := '第 &P 页';
        end;
    end;
    AssignEditProp(Footer1, EditFooter1);
    AssignEditProp(Footer2, EditFooter2);
    AssignEditProp(Footer3, EditFooter3);
  end;
end;

procedure TFormPageSetup.InsertEditText(AText: string);
var
  OldSelStart: Integer;
begin
  if not (ActiveControl is TEdit) then Exit;
  with (ActiveControl as TEdit) do
  begin
    OldSelStart := SelStart;
    Text := Copy(Text, 1, SelStart) + AText + Copy(Text, SelStart + SelLength + 1, 255);
    SelStart := OldSelStart + Length(AText);
  end;
end;

procedure TFormPageSetup.BtnInsertPageNoClick(Sender: TObject);
begin
  InsertEditText('&P');
end;

procedure TFormPageSetup.SBtnInsertPageCountClick(Sender: TObject);
begin
  InsertEditText('&C');
end;

procedure TFormPageSetup.SBtnInsertDateClick(Sender: TObject);
begin
  InsertEditText('&D');
end;

procedure TFormPageSetup.SBtnInsertTimeClick(Sender: TObject);
begin
  InsertEditText('&T');
end;

procedure TFormPageSetup.AssignEditProp(AHeader: Pointer; AEdit: TEdit);
begin
  with THeader(AHeader) do
  begin
    AEdit.Font.Name := FontName;
    AEdit.Font.Size := FontSize;
    AEdit.Font.Style := FontStyle;
    AEdit.Font.Color := FontColor;
  end;
end;

procedure TFormPageSetup.SEditFontClick(Sender: TObject);
begin
  if not (ActiveControl is TEdit) then Exit;
  FontDialogPageSetup.Font.Assign(TEdit(ActiveControl).Font);
  if FontDialogPageSetup.Execute then
    TEdit(ActiveControl).Font.Assign(FontDialogPageSetup.Font);
end;

procedure TFormPageSetup.MemoTitleContentChange(Sender: TObject);
var
  i: Integer;
begin
  FTitle.Content := '';
  with MemoTitleContent do
    for i:=0 to Lines.Count-1 do
      FTitle.Content := FTitle.Content + Lines[i];
end;

procedure TFormPageSetup.MemoTailContentChange(Sender: TObject);
var
  i: Integer;
begin
  FTail.Content := '';
  with MemoTailContent do
    for i:=0 to Lines.Count-1 do
      FTail.Content := FTail.Content + Lines[i];
end;

procedure TFormPageSetup.SEditTitleDistanceChange(Sender: TObject);
begin
  FTitle.Distance := SEditTitleDistance.Value * ScreenPixelsPerMmY;
end;

procedure TFormPageSetup.SEditTailDistanceChange(Sender: TObject);
begin
  FTail.Distance := SEditTailDistance.Value * ScreenPixelsPerMmY;
end;

procedure TFormPageSetup.BtnTitleFontClick(Sender: TObject);
begin
  FontDialogPageSetup.Font.Assign(MemoTitleContent.Font);
  if FontDialogPageSetup.Execute then
    MemoTitleContent.Font.Assign(FontDialogPageSetup.Font);
  with FTitle do
  begin
    FontName := MemoTitleContent.Font.Name;
    FontSize := MemoTitleContent.Font.Size;
    FontStyle := MemoTitleContent.Font.Style;
    FontColor := MemoTitleContent.Font.Color;
  end;
end;

procedure TFormPageSetup.BtnTailFontClick(Sender: TObject);
begin
  FontDialogPageSetup.Font.Assign(MemoTailContent.Font);
  if FontDialogPageSetup.Execute then
    MemoTailContent.Font.Assign(FontDialogPageSetup.Font);
  with FTail do
  begin
    FontName := MemoTailContent.Font.Name;
    FontSize := MemoTailContent.Font.Size;
    FontStyle := MemoTailContent.Font.Style;
    FontColor := MemoTailContent.Font.Color;
  end;
end;

procedure TFormPageSetup.BtnOkClick(Sender: TObject);

  procedure GetHeaderInfo(AHeader: THeader; AEdit: TEdit);
  begin
    with AHeader, AEdit do
    begin
      Content := Text;
      FontName := Font.Name;
      FontSize := Font.Size;
      FontStyle := Font.Style;
      FontColor := Font.Color;
    end;
  end;

  procedure GetFooterInfo(AFooter: TFooter; AEdit: TEdit);
  begin
    GetHeaderInfo(THeader(AFooter), AEdit);
  end;

var
  Grid: TEasyGrid;
begin
  if (SEditFromPage.Value > SEditToPage.Value) then
  begin
    Application.MessageBox('起始页不能大于终止页。','提示',
                           MB_OK + MB_ICONINFORMATION);
    SEditToPage.SetFocus;
    Exit;
  end;
  Grid := TEasyGrid(ParentGrid);
  with Grid.EasyGridPageInfo.DetailPageInfo, Grid.EasyGridPageInfo.CommonPageInfo do
  begin
    // 第一页上的控件
    if RBtnHPrint.Checked then
      Orientation := poLandscape
    else
      Orientation := poPortrait;
    Scale := SEditScale.Value;
    StartPageNo := SEditStartPageNo.Value;
    PrintAllPages := RBtnPrintAll.Checked;
    StartPage := SEditFromPage.Value - 1;
    EndPage := SEditToPage.Value - 1;
    PaperSize := FPaperSize;
    PageWidth := FPageWidth;
    PageHeight := FPageHeight;
    // 第二页上的控件
    Margin.Top := SEditTMargin.Value * ScreenPixelsPerMmY;
    Margin.Bottom := SEditBMargin.Value * ScreenPixelsPerMmY;
    Margin.Left := SEditLMargin.Value * ScreenPixelsPerMmX;
    Margin.Right := SEditRMargin.Value * ScreenPixelsPerMmX;
    HeaderExtent := SEditHeaderSize.Value * ScreenPixelsPerMmY;
    FooterExtent := SEditFooterSize.Value * ScreenPixelsPerMmY;
    HorzCenter := ChkBoxHorzCenter.Checked;
    VertCenter := ChkBoxVertCenter.Checked;
    // 第三页上的控件
    HeaderLineStyle := TPenStyle(CbxHLineStyle.ItemIndex);
    HeaderDoubleLine := ChkBoxHDoubleLine.Checked;
    HeaderLineWidth := SEditHLineWidth.Value;
    GetHeaderInfo(Header1, EditHeader1);
    GetHeaderInfo(Header2, EditHeader2);
    GetHeaderInfo(Header3, EditHeader3);
    FooterLineStyle := TPenStyle(CbxFLineStyle.ItemIndex);
    FooterDoubleLine := ChkBoxFDoubleLine.Checked;
    FooterLineWidth := SEditFLineWidth.Value;
    GetFooterInfo(Footer1, EditFooter1);
    GetFooterInfo(Footer2, EditFooter2);
    GetFooterInfo(Footer3, EditFooter3);
    // 第四页上的控件
    MainTitle.Assign(FMainTitle);
    Title1.Assign(FTitle1);
    Title2.Assign(FTitle2);
    Title3.Assign(FTitle3);
    Title4.Assign(FTitle4);
    Title5.Assign(FTitle5);
    Title6.Assign(FTitle6);
    Tail1.Assign(FTail1);
    Tail2.Assign(FTail2);
    Tail3.Assign(FTail3);
    Tail4.Assign(FTail4);
    Tail5.Assign(FTail5);
    Tail6.Assign(FTail6);
    TitleExtent := SEditTitleExtent.Value * ScreenPixelsPerMmY;
    TailExtent := SEditTailExtent.Value * ScreenPixelsPerMmY;
    // 第五页上的控件
    HorzSplit := RBtnHorzSplit.Checked;
    PrintConjunction := RBtnPrintConjunction.Checked;
    TopConjunctionText := EditTopConjunction.Text;
    BottomConjunctionText := EditBottomConjunction.Text;
    MonoColored := ChkBoxMonoColored.Checked;
    PrintGridLine := ChkBoxPrintGridLine.Checked;
    PrintColTitle := ChkBoxPrintColTitle.Checked;
    PrintRowTitle := ChkBoxPrintRowTitle.Checked;
    PrintFixedCols := ChkBoxPrintFixedCols.Checked;
    PrintFixedRows := ChkBoxPrintFixedRows.Checked;
  end;
  ModalResult := mrOk;
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -