我想找到需要ResponseBody body = retrofitService.retrieveImageData().execute().body();
byte[] bytes = body.bytes();
Bitmap bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
控件来呈现自身而不显示TRichEdit
的高度。
我用这个代码
vertical scrollbar
当文档有几页(< 15 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;
)时,结果就足够了。
但是有了更多的页面,rc.bottom似乎被转换,控件需要垂直滚动条。
问题是:执行代码中有一些限制吗?
如果我手动(大约)增加rc.bottom然后控件呈现自己好,但这不是我想要的情况。
PS。如果重要的话,richedit组件实际上是一个TjvRichEdit。
这是一个可以重现问题的最小程序(即使是2页)
A4 portrait
表格
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.
答案 0 :(得分:0)
最后,解决方案非常简单! TRichedit有onResizeRequest事件,其中控件的实际高度由rect参数给出