Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/delphi/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Delphi TRichEdit.Perform(EM_FORMATRANGE,0,Longint(@fmtRange));_Delphi_Trichedit - Fatal编程技术网

Delphi TRichEdit.Perform(EM_FORMATRANGE,0,Longint(@fmtRange));

Delphi TRichEdit.Perform(EM_FORMATRANGE,0,Longint(@fmtRange));,delphi,trichedit,Delphi,Trichedit,我想找到需要TRichEdit控件在不显示垂直滚动条的情况下渲染自身的高度。 我使用这个代码 function RichEditHeight(var RE : TRichEdit; aForm : TForm) : integer; var fmtRange: TFormatRange; begin FillChar(fmtRange, SizeOf(fmtRange), 0); with fmtRange do begin hDC := aForm.canvas

我想找到需要
TRichEdit
控件在不显示
垂直滚动条的情况下渲染自身的高度。
我使用这个代码

function RichEditHeight(var RE : TRichEdit; aForm : TForm) : integer;
var fmtRange: TFormatRange;
begin
    FillChar(fmtRange, SizeOf(fmtRange), 0);
    with fmtRange do begin
        hDC := aForm.canvas.Handle;
        hdcTarget := hDC;
        rc.left := 0;
        rc.right := (RE.ClientWidth * 1440) div screen.pixelsPerInch;
        rc.top := 0;
        rc.Bottom := MaxInt;
        rcPage := rc;
        chrg.cpMin := 0;
        chrg.cpMax := -1;
    end;
    RE.Perform(EM_FORMATRANGE, 0, Longint(@fmtRange));
    result := round(fmtRange.rc.Bottom*screen.pixelsPerInch/1440);
    RE.Perform(EM_FORMATRANGE, 0, 0);
end;

当文档只有几页时(最后,解决方案非常简单!
TRichedit有一个事件onResizerRequest,其中控件的实际高度由rect参数给出。我不明白这个问题。你说的“执行代码”是什么意思?在这个代码中:RE.
perform
(EM_FORMATRANGE,0,Longint(@fmtRange));很可能有限制,而不是“执行”但是控件的。使用您指定的消息和参数执行控件的窗口过程-模拟SendMessage而不发送,仅此而已。在任何显示器上,如果没有滚动条,您无法显示15页A4页面,为什么要在意呢?我使用滚动框来实现此目的。如果高度足以容纳所有页面,我可以使用scrollbox的滚动条没有欺骗它的sOk。如果你想让任何人通过复制问题来查看,请提供一个。
unit Unit32;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ComCtrls, winAPI.richedit, JvExStdCtrls, JvRichEdit, Vcl.ExtCtrls;

type
  TForm32 = class(TForm)
    ScrollBox1: TScrollBox;
    Button1: TButton;
    RichEdit1: TJvRichEdit;
    panel1: TPanel;
    OpenDialog1: TOpenDialog;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var Form32: TForm32;

implementation

{$R *.dfm}

function RichEditHeight(var RE : TjvRichEdit; aForm : TForm) : integer;
var fmtRange: TFormatRange;
begin
    FillChar(fmtRange, SizeOf(fmtRange), 0);
    with fmtRange do begin
    hDC := aForm.canvas.Handle;
    hdcTarget := hDC;
    rc.left := 0;
    rc.right := (RE.ClientWidth * 1440) div screen.pixelsPerInch;
    rc.top := 0;
    rc.Bottom := 500000;
    rcPage := rc;
    chrg.cpMin := 0;
    chrg.cpMax := -1;
    end;
    RE.Perform(EM_FORMATRANGE, 0, Longint(@fmtRange));
    result := round(fmtRange.rc.Bottom*screen.pixelsPerInch/1440);
    RE.Perform(EM_FORMATRANGE, 0, 0);
end;

procedure TForm32.Button1Click(Sender: TObject);
begin
with OpenDialog1 do
if execute then begin
    RichEdit1.lines.LoadFromFile(filename);
    panel1.height := RichEditHeight(RichEdit1,Form32);
end;
end;

end.
object Form32: TForm32
  Left = 0
  Top = 0
  Caption = 'Form32'
  ClientHeight = 615
  ClientWidth = 874
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object ScrollBox1: TScrollBox
    Left = 0
    Top = 0
    Width = 874
    Height = 615
    Align = alClient
    TabOrder = 0
    ExplicitWidth = 885
    ExplicitHeight = 583
    object Button1: TButton
      Left = 632
      Top = 24
      Width = 75
      Height = 25
      Caption = 'Button1'
      TabOrder = 0
      OnClick = Button1Click
    end
    object panel1: TPanel
      Left = 0
      Top = 0
      Width = 457
      Height = 561
      Caption = 'panel1'
      TabOrder = 1
      object RichEdit1: TJvRichEdit
        Left = 1
        Top = 1
        Width = 455
        Height = 559
        Align = alClient
        Font.Charset = GREEK_CHARSET
        Font.Color = clWindowText
        Font.Height = -11
        Font.Name = 'Tahoma'
        Font.Style = []
        ParentFont = False
        ScrollBars = ssVertical
        SelText = ''
        TabOrder = 0
        ExplicitHeight = 279
      end
    end
  end
  object OpenDialog1: TOpenDialog
    Left = 656
    Top = 88
  end
end