Jump to content
Sign in to follow this  

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;

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

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this