我需要将 GridControl 渲染到 Windows 元文件中。如果显示设置在没有缩放的情况下工作,这也可以。但是,如果我将显示设置设置为 >100% 的比例,则生成的图元文件大于控件,因此会出现边框。
应用程序清单包含以下信息,我不能更改,否则会出现其他各种显示问题。(GetProcessDpiAwareness 返回 PROCESS_DPI_UNAWARE)
<windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
<dpiAware>true</dpiAware>
</windowsSettings>
我的示例代码(在 Delphi 中):
function TForm2.CalcedRect(const p_Grid: TAdvStringGrid): TRect;
var
i : Integer;
FullWidth : Integer;
FullHeight: Integer;
begin
FullWidth := 0;
FullHeight := 0;
for i := 0 to p_Grid.ColCount - 1 do
Inc(FullWidth, p_Grid.ColWidths[i]);
for i := 0 to p_Grid.RowCount - 1 do
Inc(FullHeight, p_Grid.RowHeights[i]);
Result := Rect(0, 0, FullWidth, FullHeight);
end;
procedure TForm2.PrepareMetafile();
var
mf : TMetafile;
mfc : TMetafileCanvas;
h, w : integer;
drawRect : TRect;
begin
mf := TMetafile.Create();
try
drawRect := CalcedRect(grid1); // really used range
//drawRect := grid1.ClientRect();
w := drawRect.Width;
h := drawRect.Height;
mf.SetSize(w, h);
mfc := TMetafileCanvas.CreateWithComment(mf, HDC(0), ClassName, 'PrepareMetafile');
grid1.PaintTo(mfc, 0, 0);
FreeAndNil(mfc);
mf.SaveToFile('Grid1.emf');
StatusBar1.Panels[0].Text := Format('Grid wxh=%dx%d', [w, h]);
StatusBar1.Panels[1].Text := Format('Metafile wxh=%dx%d', [mf.Width, mf.Height]);
//--> Size of metafile is controlsize * scaling factor
except
FreeAndNil(mf);
end;
end;