Results 1 to 3 of 3

Thread: i need help about moving

  1. #1

    Thread Starter
    Hyperactive Member gaouser's Avatar
    Join Date
    Mar 2022
    Location
    Near the User32.dll
    Posts
    386

    i need help about moving

    hi guys i have 2 pictureboxes with high distance, how can i make two of those center (like when you copy two objects with diffrent x location to panel in winforms editor, it centers like they re two objects
    Basic page
    Text

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: i need help about moving

    There's no magic to it. You just have to do the basic arithmetic. If your adding a control in code and you want it to be centred horizontally in its container the you have to set its Left property appropriately, by calculating the difference between the container Width and the child control Width and halving it. You do the same thing with the Height for vertical centring. E.g.
    vb.net Code:
    1. Private Sub CentreControlInParent(child As Control)
    2.     Dim parent = child.Parent
    3.  
    4.     child.Location = New Point((parent.Width - child.Width) \ 2,
    5.                                (parent.Height - child.Height) \ 2)
    6. End Sub
    If you align two children by centre against their parent then they will be aligned by centre against each other. If you don't want to involve the parent then the arithmetic will be similar but based on just the children.

  3. #3

    Thread Starter
    Hyperactive Member gaouser's Avatar
    Join Date
    Mar 2022
    Location
    Near the User32.dll
    Posts
    386

    Re: i need help about moving

    Quote Originally Posted by jmcilhinney View Post
    There's no magic to it. You just have to do the basic arithmetic. If your adding a control in code and you want it to be centred horizontally in its container the you have to set its Left property appropriately, by calculating the difference between the container Width and the child control Width and halving it. You do the same thing with the Height for vertical centring. E.g.
    vb.net Code:
    1. Private Sub CentreControlInParent(child As Control)
    2.     Dim parent = child.Parent
    3.  
    4.     child.Location = New Point((parent.Width - child.Width) \ 2,
    5.                                (parent.Height - child.Height) \ 2)
    6. End Sub
    If you align two children by centre against their parent then they will be aligned by centre against each other. If you don't want to involve the parent then the arithmetic will be similar but based on just the children.
    idk what you talking about but i already know centering on parent code
    Last edited by gaouser; May 20th, 2022 at 08:39 AM. Reason: im taliking about 2 objects
    Basic page
    Text

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width