从lazarus源码发现,用Scale96ToForm设置控件的高和宽,可以适应不同dpi时控件尺寸保持相对大小。
FForm.Width:= FForm.Scale96ToForm(600); FForm.Height:= FForm.Scale96ToForm(400); FForm.BorderStyle:= bsDialog; FForm.Position:= poScreenCenter; FForm.Caption:= ACaption; FForm.FOnCloseEvent:= ACloseEvent;
还有不同的转换:
//scale support function ScaleDesignToForm(const ASize: Integer): Integer; function ScaleFormToDesign(const ASize: Integer): Integer; function Scale96ToForm(const ASize: Integer): Integer; function ScaleFormTo96(const ASize: Integer): Integer; function Scale96ToFont(const ASize: Integer): Integer; function ScaleFontTo96(const ASize: Integer): Integer; function ScaleScreenToFont(const ASize: Integer): Integer; function ScaleFontToScreen(const ASize: Integer): Integer; function Scale96ToScreen(const ASize: Integer): Integer; function ScaleScreenTo96(const ASize: Integer): Integer;

浙公网安备 33010602011771号