dcsimg
Results 1 to 8 of 8

Thread: [RESOLVED] Center Picture2 in Picture1

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2017
    Posts
    192

    Resolved [RESOLVED] Center Picture2 in Picture1

    How do I center Picture2 inside of Picture1

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

  2. #2
    Hyperactive Member
    Join Date
    Feb 2019
    Posts
    484

    Re: Center Picture2 in Picture1

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

  3. #3
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    13,020

    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. #4
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,580

    Re: Center Picture2 in Picture1

    Quote Originally Posted by DataMiser View Post
    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. #5

    Thread Starter
    Addicted Member
    Join Date
    Mar 2017
    Posts
    192

    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.....
    Attached Images Attached Images  

  6. #6
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,580

    Re: Center Picture2 in Picture1

    Quote Originally Posted by Ordinary Guy View Post
    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.....
    See my above reply #4



  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Mar 2017
    Posts
    192

    Re: Center Picture2 in Picture1

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

  8. #8
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,580

    Re: Center Picture2 in Picture1

    Quote Originally Posted by Ordinary Guy View Post
    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
  •  



Featured


Click Here to Expand Forum to Full Width