Jump to content


Centering zoomed objects

  • Please log in to reply
No replies to this topic

#1 Czar

  • Members
  • 149 posts

Posted 04 June 2017 - 11:40 PM

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;

  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);

  • Nico Wouterse likes this

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users