Thread: [RESOLVED] Center Picture2 in Picture1

1. [RESOLVED] Center Picture2 in Picture1

How do I center Picture2 inside of Picture1

Code:
``` +------------------------------+
|      Picture1                |
|                              |
|                              |
|       +-------------+        |
|       |Picture2     |        |
|       |             |        |
|       |             |        |
|       |             |        |
|       +-------------+        |
|                              |
|                              |
|                              |
+------------------------------+```

2. Re: Center Picture2 in Picture1

Use the Move method of Picture2, to both move it and resize it at the same time.

3. Re: Center Picture2 in Picture1

Use something along the lines of

Code:
```top= (Picture1.ScaleHeight-picture2.height)/2
left=(picture1.scalewidth-picture2.width)/2```

4. Re: Center Picture2 in Picture1

Originally Posted by DataMiser
Use something along the lines of

Code:
```top= (Picture1.ScaleHeight-picture2.height)/2
left=(picture1.scalewidth-picture2.width)/2```
That code is OK if Picture1 is parent of Picture2, if it isn't then you should use the following code
Code:
```Picture2.Left = Picture1.Left + (Picture1.Width / 2) - (Picture2.Width / 2)
Picture2.Top = Picture1.Top + (Picture1.Height / 2) - (Picture2.Height / 2)```

5. Re: Center Picture2 in Picture1

Using this code.....

top= (Picture1.ScaleHeight-picture2.height)/2
left=(picture1.scalewidth-picture2.width)/2

Picture1.Width = 514
Picture1.Height = 327

Picture2.Width = 65
Picture2.Height = 18

Both pictures have ScaleMode Pixels

this is what I get.....

6. Re: Center Picture2 in Picture1

Originally Posted by Ordinary Guy
Using this code.....

top= (Picture1.ScaleHeight-picture2.height)/2
left=(picture1.scalewidth-picture2.width)/2

Picture1.Width = 514
Picture1.Height = 327

Picture2.Width = 65
Picture2.Height = 18

Both pictures have ScaleMode Pixels

this is what I get.....

7. Re: Center Picture2 in Picture1

OK, never mind post 5 I now see post 4. Everything OK now

8. Re: Center Picture2 in Picture1

Originally Posted by Ordinary Guy
OK, never mind post 5 I now see post 4. Everything OK now
I think you have to think of setting Picture1 as parent of Picture2, this may save you a lot of extra calculation if you move both relatively, to do at run time
Code:
```Private Sub Form_Load()
Set Picture2.Container = Picture1
End Sub```
or at design time by cutting Picture2 and pasting it inside Picture1

Posting Permissions

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