Delphi Programming / Object Pascal
サイトのトップページへ リンクのページへ ロゴマーク
[掲載 2000年12月12日] [更新 2016年04月19日] 印刷プレビュー制御コンポーネント
   
印刷プレビュー制御コンポーネント
テストプログラム TextRect
動作確認等 Windows 7 U64(SP1) + Delphi XE(UP1) Pro







矩形領域内の文字列描画 ( 先読み方式 )


追加メソッドの,矩形領域内の文字列描画のテストです.ただそれだけです.


図1
設計時画面
図2
実行画面
  • コードで印刷方向を横にしている

リスト1
テストプログラムのコード
unit TextRectUnit;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, plPrev, Buttons;

type
  TForm1 = class(TForm)
    SpeedButton1: TSpeedButton;
    plPrev1: TplPrev;
    procedure SpeedButton1Click(Sender: TObject);
  private
    { Private 宣言 }
  public
    { Public 宣言 }
  end;

var
  Form1: TForm1;

implementation

uses
  Printers;

{$R *.DFM}

//=============================================================================
//  矩形を描き,そこを基準にしてルーチン名(メソッド名)と同じ文字列を描画
//  このコードは先読み方式(BeginDoc~,EndDocを使用している)
//=============================================================================
procedure TForm1.SpeedButton1Click(Sender: TObject);
var
  LX1     : Integer;
  LX2     : Integer;
  LY1     : Integer;
  LY2     : Integer;
  LYStart : Integer;
  LYh     : Integer;
  LXw     : Integer;
  LXdis   : Integer;
  LYdis   : Integer;
begin
  //プリンタの設定を以下のように実行時に変更可能
  plPrev1.plSetPrinter.Orientation := poLandscape;

  plPrev1.BeginDoc;
  try
    plPrev1.FontSize(30);
    //日本語の文字列描画の時は日本語のフォント名を指定すること
    plPrev1.FontName('Courier New');
    plPrev1.PenWidth(1);
    plPrev1.PenColor(clBlue);

    LXw     := 720;
    LYh     := 200;
    LXdis   := LXw + 50;
    LYdis   := LYh + 80;
    LYStart := 300;

    //矩形の左上から描画
    LX1  := 150;
    LX2  := LX1 + LXw;
    LY1  := LYStart;
    LY2  := LY1 + LYh;
    plPrev1.Rectangle(LX1, LX2, LY1, LY2);
    plPrev1.TextRectLT(LX1, LX2, LY1, LY2, 'TextRectLT');

    //矩形の左端から描画
    LY1  := LY1 + LYdis;
    LY2  := LY1 + LYh;
    plPrev1.Rectangle(LX1, LX2, LY1, LY2);
    plPrev1.TextRectLC(LX1, LX2, LY1, LY2, 'TextRectLC');

    //矩形の左下から描画
    LY1  := LY1 + LYdis;
    LY2  := LY1 + LYh;
    plPrev1.Rectangle(LX1, LX2, LY1, LY2);
    plPrev1.TextRectLB(LX1, LX2, LY1, LY2, 'TextRectLB');

    //矩形の左右中央で上端に寄せて描画
    LX1  := LX1 + LXdis;
    LX2  := LX1 + LXw;
    LY1  := LYStart;
    LY2  := LY1 + LYh;
    plPrev1.Rectangle(LX1, LX2, LY1, LY2);
    plPrev1.TextRectCT(LX1, LX2, LY1, LY2, 'TextRectCT');

    //矩形の左右中央に描画
    LY1  := LY1 + LYdis;
    LY2  := LY1 + LYh;
    plPrev1.Rectangle(LX1, LX2, LY1, LY2);
    plPrev1.TextRectCC(LX1, LX2, LY1, LY2, 'TextRectCC');

    //矩形の左右中央で下端に寄せて描画
    LY1  := LY1 + LYdis;
    LY2  := LY1 + LYh;
    plPrev1.Rectangle(LX1, LX2, LY1, LY2);
    plPrev1.TextRectCB(LX1, LX2, LY1, LY2, 'TextRectCB');

    //矩形の右上に寄せて描画
    LX1  := LX1 + LXdis;
    LX2  := LX1 + LXw;
    LY1  := LYStart;
    LY2  := LY1 + LYh;
    plPrev1.Rectangle(LX1, LX2, LY1, LY2);
    plPrev1.TextRectRT(LX1, LX2, LY1, LY2, 'TextRectRT');

    //矩形の右端に寄せて描画
    LY1  := LY1 + LYdis;
    LY2  := LY1 + LYh;
    plPrev1.Rectangle(LX1, LX2, LY1, LY2);
    plPrev1.TextRectRC(LX1, LX2, LY1, LY2, 'TextRectRC');

    //矩形の右下に寄せて描画
    LY1  := LY1 + LYdis;
    LY2  := LY1 + LYh;
    plPrev1.Rectangle(LX1, LX2, LY1, LY2);
    plPrev1.TextRectRB(LX1, LX2, LY1, LY2, 'TextRectRB');
  finally
    plPrev1.EndDoc;
  end;

  //プレビュー開始
  plPrev1.ShowModal;
end;

end.