'VBA Userform: Text of same font size changes size based on Top property

I have a userform. In multiple cases across several different controls, I have observed the objects with the same Width, Height, Font, and Font Size display different font sizes depending on where they are placed on my userform.

Example as seen . . . . Example with dots to show measurements

Above is an example of this. The two textbox's are both 26H and 48W, with a Left of 90. Both have font Tahoma Regular size 18. The only difference between them is their Top property. And yet visually, the upper one has much wider text than the lower one. The picture on the right has added dots to prove this is not an optical illusion. The upper one can only fit one dot between the letter and the edge. The lower one can fit at least two dots between the letter and the edge.

Can anyone explain why this is happening? What is happening? Or how I could stop it from happening?



Solution 1:[1]

Why its happening?

A normal windows graphical application renders in 96dpi/ppi. However, excel’s rendering system is in 72dpi/ppi,so, when you specify 26 as the height, excel will first convert 72 to 96 dpi.

26 x 96 / 72 = 34.6667

Which means your control height is 34.667 pixels. This will create artefacts in the rendering of your control.

How can you stop it?

Make sure that the final position of your control and its height has a final pixel position in the form to be a whole number.

You can do this by multiplying by your screen dpi and divide by excel dpi(72)

In your case you can apply a height of 25.5 which will render it correctly.

I hope I solved your answer!!

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1