How to properly size a userform background picture?

User avatar
kdock
5StarLounger
Posts: 720
Joined: 21 Aug 2011, 21:01
Location: The beautiful hills of Western North Carolina

How to properly size a userform background picture?

Post by kdock »

This is something that often befuddles me. I'm using Word vba.

Let's say I have a UserForm with a Width of 300, Height of 200. I want set a background picture to fill this space.

In the past, I would set PictureAlignment to upper right, set PictureSizeMode to Clip and that was that. Now, with the ability of Windows 7 users to set their display resolution to, say, 125%, that doesn't work so well any more -- even though other controls resize automatically, the background picture does not.

I can fix this by using stretch instead of clip, but I risk the graphic becoming distorted. So, I try to set the image to the right proportions to begin with. Yes, it will be pixelated when it's stretched to 125%, but at least it will not look too sort and too wide.

But. I can't. For the life of me. Figure out. How to turn Width=300, Height=200 into pixels, inches, twips, or anything else that actually works in a graphics manipulation program. So...

Does anyone know anything/have any wisdom about this? How tall is the Title bar, for example? Do I need to subtract that measurement from the total height of the UserForm? Does this measurement presume 100 ppi or 96 or some other unit of measure? Is this actually written down anywhere? I came close today and simply decided to change my dialog dimensions to match the image, but that is not a good solution in the long run.

Any help would be most appreciated!

Thanks, Kim :hairout:
"Hmm. What does this button do?" Said everyone before being ejected from a car, blown up, or deleting all the data from the mainframe.

User avatar
HansV
Administrator
Posts: 78545
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: How to properly size a userform background picture?

Post by HansV »

You may be able to use the InsideWidth and InsideHeight properties of the userform; these are the dimensions of the "usable" area of the userform in points; for a 300 x 200 userform, I get InsideWidth=295.5 and InsideHeight=179.25. You'll note that the borders take 4.5 points away from the width; assuming that they take away the same amount from the height, the title bar must be 200-4.5-179.25=16.25 points high.
Best wishes,
Hans

User avatar
kdock
5StarLounger
Posts: 720
Joined: 21 Aug 2011, 21:01
Location: The beautiful hills of Western North Carolina

Re: How to properly size a userform background picture?

Post by kdock »

First, I've never stumbled over InsideWidth or InsideHeight. Hallelujah Hans, and thanks!

I almost always over think math word problems, but if the right and left borders together take away 4.5 from the width, wouldn't the bottom border be half that, or 2.25? So the title bar should be 200-2.25-179.25=18.5?

Thank you thank you! I'm going to try these dimensions right now and see what happens.

Best, Kim
"Hmm. What does this button do?" Said everyone before being ejected from a car, blown up, or deleting all the data from the mainframe.

User avatar
kdock
5StarLounger
Posts: 720
Joined: 21 Aug 2011, 21:01
Location: The beautiful hills of Western North Carolina

Re: How to properly size a userform background picture?

Post by kdock »

Well, it doesn't quite work, whatever the math.

Using my 300W x 200H form, I created a graphic 295 x 179 with resolution at 100 -- my quickie program wouldn't allow fractions, but I figured this would get me close enough. Here's the result:
userform image.png
Too small, but the proportions look pretty good. So I experimented making it bigger and after some testing, found that expanding the graphic by just between 128% and 129% makes it fit pretty neatly into the inside dimensions of the UserForm.
userform image 2.png
In fact, I think that because my program can't deal with fractions and I made my original image just slightly smaller, that 128% is just about the perfect size. So I can size the background, then add text elements, knowing they will at least not be distorted to begin with.

Thank you thank you thank you again Hans! :thankyou:
You do not have the required permissions to view the files attached to this post.
"Hmm. What does this button do?" Said everyone before being ejected from a car, blown up, or deleting all the data from the mainframe.

User avatar
HansV
Administrator
Posts: 78545
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: How to properly size a userform background picture?

Post by HansV »

kdock wrote:So the title bar should be 200-2.25-179.25=18.5?
That's a matter of definition: 18.5 would be the height of the title bar including the top border, 16.25 without the top border...
Best wishes,
Hans

User avatar
kdock
5StarLounger
Posts: 720
Joined: 21 Aug 2011, 21:01
Location: The beautiful hills of Western North Carolina

Re: How to properly size a userform background picture?

Post by kdock »

Yes, of course. I knew I was missing something...

Thanks again, Kim
"Hmm. What does this button do?" Said everyone before being ejected from a car, blown up, or deleting all the data from the mainframe.