要求:
  将一段文字Mystr(动态加载)打印在A2纸中的 left:50mm;top:30mm;rigth:150mm;bottom:80mm这块区域上,Mystr的字体大小是自动随着他的length改变的,但最大字体为24,当Mystr内容添多时,算法会判断内容是否能完整地打印在该区域,如果不能自动将字体调小一点直到使用该段内容完整地打印该区域.这我愚作,请高手批评我.主程序
-----------------------------------------
unit Unit1;
interface
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls,printers;
type
  TForm1 = class(TForm)
    Edit1: TEdit;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Memo5: TMemo;
    Label1: TLabel;
    Memo2: TMemo;    procedure Button3Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;var
  Form1: TForm1;implementationuses Unit_print;{$R *.dfm}
 function MmToxpoint(length: extended): integer;
              begin
             // MmToxpoint:=round(Screen.PixelsPerInch*(length/25.4));
                             MmToxpoint:=round(HPointsPerInch*(length/25.4));              end;procedure TForm1.Button3Click(Sender: TObject);
    function pxtomm(x:integer):integer;
    begin
    //   result:=round((Abs(x)/screen.PixelsPerInch)*25.4)
       result:=round((Abs(x)/VPointsPerInch)*25.4)
    end;var
i,iposy:integer;
begin
//=======设置memo的长高
Memo2.Width:=MmToxpoint(50);
Memo2.Height:=MmToxpoint(50);//=======================字体
memo2.Font.Size:=18;
Memo2.Perform(WM_VSCROLL,SB_BOTTOM,0);  while GetScrollPos(Memo2.Handle, SB_VERT)>0 do
  begin
    if Memo2.Font.Size=1 then break;
    Memo2.Font.Size := Memo2.Font.Size - 1;
  end;//=======================打印
        setnewprint;
        printer.Title:='test';
        printer.BeginDoc;
        for i:=0 to memo2.Lines.Count-1 do
        begin
        iposy:=i*pxtomm(memo2.Font.Height);
        printtext(50,40+iposy,memo2.Lines[i],memo2.Font);//打印
        end;
        printer.EndDoc;end;end.窗体
--------------------------------------------------------------------------
object Form1: TForm1
  Left = 202
  Top = 107
  Width = 661
  Height = 573
  Caption = 'Form1'
  Color = clBtnFace
  Font.Charset = ANSI_CHARSET
  Font.Color = clWindowText
  Font.Height = -24
  Font.Name = '宋体'
  Font.Style = []
  OldCreateOrder = False
  OnCreate = FormCreate
  PixelsPerInch = 96
  TextHeight = 24
  object Label1: TLabel
    Left = 16
    Top = 72
    Width = 19
    Height = 19
    Caption = '■'
    Font.Charset = ANSI_CHARSET
    Font.Color = clWindowText
    Font.Height = -19
    Font.Name = '宋体'
    Font.Style = []
    ParentFont = False
  end
  object Edit1: TEdit
    Left = 392
    Top = 424
    Width = 121
    Height = 32
    TabOrder = 0
    Text = 'Edit1'
    Visible = False
  end
  object Button1: TButton
    Left = 600
    Top = 416
    Width = 75
    Height = 25
    Caption = 'Button1'
    TabOrder = 1
    Visible = False
  end
  object Button2: TButton
    Left = 520
    Top = 416
    Width = 75
    Height = 25
    Caption = 'Button2'
    TabOrder = 2
    Visible = False
  end
  object Button3: TButton
    Left = 456
    Top = 48
    Width = 105
    Height = 33
    Caption = '打印'
    TabOrder = 3
    OnClick = Button3Click
  end
  object Memo5: TMemo
    Left = 560
    Top = 344
    Width = 185
    Height = 65
    Lines.Strings = (
      
        '  1608卡是一种带认证功能的逻辑加密卡,共有8个用户数据区,每一个区有256字节,一个配置区,用于存放认证数据及读写密码用。' +
        '用户区也可动态分配为任意小于8个的区。使用比较方便。AT88SC153为三个用户区(每区为64个字节)的功能特别相近的一种逻辑加' +
        '密卡。AT88SC1601是加密存储卡,容量为16K bit。整卡分为一个公用区和四个应用区,个人化之前,整个卡的访问受总密码和' +
        '读写保护位的控制。个人化之后,各区的读、写和擦除都要受总密码、分区密码、分区擦除密码和读写保护位的控制。1604 与1601卡基' +
        '本相同,它们的区别是:各个分区的容量不同;1601只是1区有密码计数器 ,而1604的4个分区都有密码计数器。')
    TabOrder = 4
    Visible = False
    WordWrap = False
  end
  object Memo2: TMemo
    Left = 80
    Top = 0
    Width = 321
    Height = 313
    Lines.Strings = (
      '3. 表明自己的立场已经处在'
      '管理解决方案的市场,以及在'
      '这个业务中会将哪些工作留给'
      '合作伙伴。'
      '4. 向开发者快速提供下一代'
      '支持Vista的基本工具。'
      '5. 推动该公司的在线策略,'
      '比如建立新的广告平台,并向'
      '小型企业进行宣传。'
      '6. 协调自己的企业资源计划'
      '策略,让合作伙伴能够提供支'
      '持,进行销售,并把新用户转'
      '到该公司新命名的Dynamics产'
      '品线。'
      '7. Dynamic Systems '
      'Initiative,这是一个潜在的'
      '问题,就是让软件管理其它软'
      '件的标准。继续发展文件组件'
      ',比如Systems Definition '
      'Model,创建并开发相关的开'
      '发者工具。'
      '8. 建立起自己的产品发布策'
      '略,并显示出执行它的决心。'
      '9. 在同竞争对手的较量中证'
      '明Xbox 360的高定价策略;为'
      '用户开发一款必玩的Xbox游戏'
      ';消除Xbox短缺的现象,排除'
      '先前出现的小故障。 ')
    TabOrder = 5
  end
end在这里贴不完,详细代码
http://www.seion.com.cn/Memo_Auto_size.rar谢谢各位高手的光顾.帮出出点子:)
end.