Expected behavior with RectControl.LockLeft or Lockright e.g. resizing

If I resize a window I would my controls to stay in a relative position.
If however, I want them to move, it seems RectControl.LockLeft will override a new positioning.
For Instance these 2 controls don’t appear relative to the center and next to each other relatively,
but on the other side, because of horizontal locking

PrevNextButton.Left = self.Width\\2 - PrevNextButton.Width - 50 PNText.Left = PrevNextButton.Left - PNText.Width - 20 CloseBtn.Left = self.Width\\2 + 50
Is this expected?

Any/All sides that you LOCK will remain in place during a normal RESIZE event.
however if you explictily change ANY of the values (left, top,width or right), then those values will be changed

WHERE are you putting the code

and to center it should be

 PrevNextButton.Left = (self.Width - PrevNextButton.Width)/2
  PNText.Left = PrevNextButton.Left - PNText.Width - 20
  CloseBtn.Left =( self.Width-closeBtn.width)/2

that is assuming I understand your desired result :slight_smile:

Hmm. I don’t have to use Mod?

Yes. I’m trying to get the controls 50 off from the center.
I have the Locks on opposite ends. The CloseBtn has the lock on the left and the others are right.
They flip sides, and override the new resized locations.

If you set LEFT then the LEFT lock doesn’t matter
Lock controls how or if a RESIZE event moves the control, not if YOU set the values

That is like, unlocking the control, moving it, and locking it again

Thanks I wasn’t finding that piece in RectControl LockLeft in the LR.
Would you unlock and relock. What happens if not? Can they float?

Not sure what part you are not understanding…
your code can change them even if they are locked…

LOCKxxx affects behaviour of RESIZE events, NOT anything else your code does

I am trying to prevent this. From what you wrote, I don’t need to set lock=false to move them.
The first image is original. The second is resized.


then your original code is correct

 PrevNextButton.Left = (self.Width\\2) - PrevNextButton.Width - 50
  PNText.Left = PrevNextButton.Left - PNText.Width - 20
  CloseBtn.Left =( self.Width\\2) + 50
  • move PrevNextButton 50px to the left of Center
  • move PnText 20px to left of PrevNextButton
  • Move CloseBtn 50 px to the right of center

So… back to your original question, now we know your intent.

and I’ll ask one more time… WHERE are you putting this code


If you do nothing but lock bottom and left , the Prev/Next and arrow buttons will stay at a certain distance from the left
If you lock the close button right and bottom, it will move to keep pace with the right edge
A big window ill have a big gap between them.
A small window may cause them to overlap

If you want them to all stay in a group, and have the group move around,
probably best put them in a container control, and just move that in code, after the resize event

Mycontainer.left = (width - Mycontainer.width)/2

Dave. Sorry. Missed the Where? It is in the open.

Thanks Jeff. For some reason I was trying to do it cheaply and didn’t think of a containerControl. That is what I need to do.
Thanks. So that is expected behavior.

Well there is your problem. It never gets redone if you resize the window
even a container control won’t fix that