-
May 19th, 2022, 01:13 PM
#1
Thread Starter
Hyperactive Member
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
-
May 19th, 2022, 09:02 PM
#2
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:
Private Sub CentreControlInParent(child As Control)
Dim parent = child.Parent
child.Location = New Point((parent.Width - child.Width) \ 2,
(parent.Height - child.Height) \ 2)
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.
-
May 20th, 2022, 08:37 AM
#3
Thread Starter
Hyperactive Member
Re: i need help about moving
Originally Posted by jmcilhinney
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:
Private Sub CentreControlInParent(child As Control)
Dim parent = child.Parent
child.Location = New Point((parent.Width - child.Width) \ 2,
(parent.Height - child.Height) \ 2)
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|