VBA - 用户窗体上控制字体的奇怪问题

发布于 2024-08-14 14:41:08 字数 911 浏览 1 评论 0原文

我有一个 VBA UserForm (在 Word 文档中),它在 Frame 控件内有一些 CheckBox 控件。

我的所有 CheckBox 控件都设置为使用 Tahoma 字体(控件的默认字体),但其中之一显示为 Verdana。也就是说,它在属性对话框中显示 Tahoma,但实际用于显示文本的字体是 Verdana(无论是在设计时还是在运行时)。

[现在,我应该提到,我确实在字体上搞乱了一段时间,Verdana 是我曾经使用过的字体之一,但现在我已将所有内容设置回 Tahoma。]

你可能在想 - 只是删除并重新创建复选框。试过了。我还尝试复制正确显示的复选框之一。没有喜悦。

这是真正疯狂的事情:CheckBox(或我创建的任何其他CheckBox)仅当它位于表单上的特定位置时才显示为Verdana。如果我将其向上或向下移动几个档次,那就没问题了。 任何我移动到这个特定位置的复选框都会神奇地显示为 Verdana,直到我将其移动到其他位置。不幸的是,我需要它处于那个位置(而不是 Verdana)!

我已经为此奋斗了几个小时,并尝试导出和重新导入代码,另存为 Word 2007 文档(我最初使用的是 2003),除了从头开始重新创建表单之外,我能想到的一切不想做,因为它太大了)。

我认为表单存在某种损坏,但保存的 .frx 文件是二进制格式,因此我无法检查(或编辑)它。

有人见过这个问题吗?有什么解决方案吗?

编辑:我上面说过问题 CheckBox 显示为 Verdana。这是不正确的。我通过反复试验确定它实际上是Tahoma - 但在9pt而不是8pt。上面的其他内容仍然有效,但问题在于文本的大小,而不是字体。

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 design 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

绮烟 2024-08-21 14:41:08

我的一位同事也遇到了同样的问题,并发现如果更改受影响的表单域的大小(使其稍微高一点),问题就会消失。 (为什么???!)

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???!)

梓梦 2024-08-21 14:41:08

当框架内有复选框时,我也经历过同样的情况。一些复选框变得很小,但不是全部,框架上半部分的复选框保持不变。

通过将框架的字体大小属性更改为更大的字体大小,这个问题神奇地从复选框中消失了。

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.

对不⑦ 2024-08-21 14:41:08

文本显示不正确的问题是由“网格”造成的。仅当控件的顶部位置与 6 的倍数对齐时,文本才会正确显示。我确实使用以下方法来避免此类问题:

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

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
很糊涂小朋友 2024-08-21 14:41:08

事实证明,这种行为甚至与 Walter 所经历的 6 的倍数无关,至少在我的例子中是这样。特定复选框的 Top 参数设置为 112,Tahoma 字体似乎比显示的字体设置大 1 磅(我多次更改设置,通常与其他复选框的设置一致,以确保它是预期的 10)。将 Top 参数更改为 110 会导致字体以正确的大小显示,但将 Top 设置为 111 和 113 也是如此。显然,将 Top 设置为 112 是一种不好的情况,至少在这个用户窗体中是这样。这个问题有时很明显,而其他时候则不明显,所以,这意味着......?

再加上一些用户窗体在运行时自行调整大小的小精灵(在运行时之后在编辑器中查看对象时拖动右下角,所有控件都会恢复到正确的大小/位置,但需要将用户窗体重置回预期的高度/宽度;哦,并且不要在编辑器中显示对象的情况下运行代码以避免出现此问题),编辑器的行为变得有点累。

Turns out the behaviour is not even related to multiples of 6 as Walter experienced, at least in my case. The Top parameter of a particular checkbox was set to 112, and the Tahoma font appeared to be 1 point larger than the font settings showed (and I changed the setting several times, often in concert with other checkboxes' settings, to make sure it was the intended 10). Changing the Top parameter to 110 caused the font to display at the correct size, but so did setting Top to 111 and 113. Apparently a Top setting of 112 is a no-bueno situation, at least in this userform. The issue has been noticeable at times, and not at others, so, this means ... ?

Coupled with some userform-self-resizing-at-runtime gremlins (drag the bottom-right corner when viewing the Object in the Editor after runtime and all of the controls snap back to the correct size/place, but requires resetting the userform back to the intended height/width; oh, and don't run the code with the Object visible in the Editor to avoid the issue altogether), the Editor's behaviour is getting a bit tiring.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文