停止缩放TGraphicControl组件

这是我的组件构造函数:

constructor TDiskMap.Create(AOwner: TComponent);
begin
 inherited Create(AOwner);
 FCellSize:= 13; FCellsH:= 10; FCellsV:= 10;
 Width:= (FCellsH * FCellSize) + 1;
 Height:= (FCellsV * FCellSize) + 1;
end;

When I run the application, the size of the control is not the one that I set in the constructor, because it is scaled after that. I want to take care myself of scaling and disable this autos-scaling, but TGraphicControl has no Scaled property. I tried to hook WM_SIZW, WM_MINMAXINFO, use Constrains... but no effect. Any ideas ? I want that no one could automatically resize the control, except me. And I mean at the pixel level... regardless of dpi.

评论
  • walias
    walias 回复

    To react on scaling you need to override ChangeScale - to be precise, the three parameter overload of it.

    If you don't want the default scaling behavior of the control you should avoid calling inherited in your derived method and handle all necessary calculations by yourself.

    请注意,这仅在应用程序首先识别dpi时才有效。