开发者

VBA - weird problem with control font on UserForm

开发者 https://www.devze.com 2022-12-14 06:13 出处:网络
I have a VBA UserForm (in a Word document), that has some CheckBox controls inside a Frame control. All of my CheckBox controls are set to use the Tahoma font (the default for controls), but one of t

I have a VBA UserForm (in a Word document), that has some CheckBox controls inside a Frame control.

All of my CheckBox controls are set to use the Tahoma font (the default for controls), but one of them is showing as Verdana. That is, it says Tahoma in the properties dialog, but the font actually used to display the text is Verdana (both at des开发者_如何学JAVAign time and at run time).

[Now, I should mention that I did mess around with the fonts for a while, and Verdana was one of the fonts I used at one point, but now I've set everything back to Tahoma.]

You're probably thinking - just delete and re-create the CheckBox. Tried that. I also tried copying one of the CheckBoxes that displays correctly. No joy.

Here's the really crazy thing: the CheckBox (or any other CheckBox I create) only shows as Verdana if it's at a particular position on the form. If I move it up or down a couple of notches, it's fine. Any CheckBox I move into this particular position magically shows as Verdana until I move it somewhere else. Unfortunately, I need it to be in that position (and not be Verdana)!

I've battled with this for hours, and tried exporting and re-importing the code, saving as a Word 2007 document (I was originally using 2003), everything I can think of short of re-creating the form from scratch (which I don't want to do, as it's huge).

I presume that there's some sort of corruption of the form, but the saved .frx file is in a binary format, so I can't check (or edit) it.

Anyone seen this problem? Any solutions out there?

EDIT: I said above that the problem CheckBox shows as Verdana. That's not correct. I've established by trial-and-error that it's actually Tahoma - but at 9pt instead of 8pt. Everything else above still holds, but the problem is with the size of the text, not the font face.


One of my colleagues had the same problem, and discovered that if you change the size of the affected formfield (making it fractionally taller), it makes the problem go away. (Why???!)


I experienced the same when having checkboxes inside a frame. Some of the checkboxes became tiny, but not all, the ones in the top half of the frame remained unchanged.

By changing the fontsize property of the frame to a bigger fontsize, this issue magically disappeared from the checkboxes.


The trouble with incorrectly displayed text results from the "grid". Text is only correctly displayed when the top position of a control aligns with a multiple of 6. I do use the following to avoid such problems:

Public Function AdjustedToVerticalGrid(ByVal atvg_si As Single, _
                          Optional ByVal atvg_threshold As Single = 1.5, _
                          Optional ByVal atvg_grid As Single = 6) As Single
' -------------------------------------------------------------------------------
' Returns an integer which is a multiple of the grid value (stvg_grid)
' considering a certain threshold (atvg_threshold) which defaults to 1.5. The
' result vertically aligns a control in a userform to a grid value which ensures
' that a text within the control is correctly displayed in accordance with its
' font size. A threshold (atvg_threshold) of 1.5 - the default - with a grid
' value (atvg_grid) of 6 - the default - means:
'  7.5 < si >= 0   results to 6
' 13.5 < si >= 7.5 results in 12
' -------------------------------------------------------------------------------
    AdjustedToVerticalGrid = (Int((atvg_si - atvg_threshold) / atvg_grid) * atvg_grid) + atvg_grid
End Function
0

精彩评论

暂无评论...
验证码 换一张
取 消