Results 1 to 4 of 4

Thread: Resize Image Control at runtime

  1. #1

    Thread Starter
    Super Moderator Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    11,998

    Resize Image Control at runtime

    I am stuck in a very peculiar situation. Seems like no one has ever asked this question before or maybe I am not able to search for it.

    There is a Userform in Excel. It has an Image Control. It's PitcutreSizeMode = fmPictureSizeModeClip. I know I can change the PitcutreSizeMode to Zoom or Stretch but I do not want to do that. What I want is at runtime, the size of the control should resize to match the image's size. The image is already embeded inside the Image control. I do not want to use the relative path of the image.

    Let's say we have the following measurements when the userform is initialized

    Image1.Height: 54
    Image1.Width: 84

    Image1.Picture.Width: 5821
    Image1.Picture.Height: 3874

    This is what I am trying to achieve.

    Name:  Untitled.jpg
Views: 158
Size:  39.2 KB

    Any idea on how do I proceed with this?
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved

    Microsoft MVP: 2011 - 2015 IMP Links : Acceptable Use Policy, FAQ
    MyGear:
    OMEN by HP - 15-ce073tx with Win10+Office 2013. || Mac Book Pro (10.6.8) with Office 2011

  2. #2
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,304

    Re: Resize Image Control at runtime

    Can you change the size mode to Auto?
    Edit: I guess not...
    But you can set Autosize to True.
    Last edited by passel; Aug 23rd, 2019 at 05:26 PM.

  3. #3

    Thread Starter
    Super Moderator Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    11,998

    Re: Resize Image Control at runtime

    Autosize = True will not help. It is already set to Autosize = True at design time. I then resize the control and make it very small. I want to resize it at runtime.
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved

    Microsoft MVP: 2011 - 2015 IMP Links : Acceptable Use Policy, FAQ
    MyGear:
    OMEN by HP - 15-ce073tx with Win10+Office 2013. || Mac Book Pro (10.6.8) with Office 2011

  4. #4

    Thread Starter
    Super Moderator Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    11,998

    Re: Resize Image Control at runtime

    Ok you gave me an idea. It does solve the problem and for that due credit to you (rated your answer)

    I set the Autosize = False and then set it to true in UserForm_Initialize()

    Code:
    Private Sub UserForm_Initialize()
        imgMain.AutoSize = True
           
        Me.Width = imgMain.Width + 10
        Me.Height = imgMain.Height + 10
    End Sub
    I am also interested to see a solution which involves pixel/point handling as per a user's system config (DPI).
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved

    Microsoft MVP: 2011 - 2015 IMP Links : Acceptable Use Policy, FAQ
    MyGear:
    OMEN by HP - 15-ce073tx with Win10+Office 2013. || Mac Book Pro (10.6.8) with Office 2011

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