Jump to content

Centering zoomed objects


Recommended Posts

I was having difficulty centring a panel on the screen when zoom>1.

 

It took me a little while to work out what was going on so I thought I would post a solution in case other people get a bit stuck on the same issue.

 

In this example I had two panels, one zoom=1 and zoom=2

 

It turns out that the area that you are centring on is being zoomed.

procedure TForm1.Resize;
begin
  inherited;

  panelzoom.zoom := 2;
  panelzoom.left := trunc(self.ClientWidth / (2*panelzoom.zoom)) -  (panelzoom.width div 2);
  panelzoom.top :=  trunc(self.ClientHeight / (2*panelzoom.zoom)) -  (panelzoom.Height div 2);



  panelnotzoom.left := (self.ClientWidth div 2) -  (panelnotzoom.width div 2);
  panelnotzoom.top := (self.ClientHeight div 2) -  (panelnotzoom.Height div 2);
end;
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...