更改字体大小以适合标签尺寸。 [英] Change font size to fit label dimensions.

查看:207
本文介绍了更改字体大小以适合标签尺寸。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的标签尺寸W =宽度& H =高度。它最初有4个单词的30个字母的标题,每个单词由空格或换行符分隔。最初标签的大小与所选字体中的标题大小相当。


使用VBA,我现在想要将标题更改为5个单词中的45个字母。

使用已故的Stephen Leban的fTextWidthOrHeight例程,我可以用相同的字体获得新措辞的宽度和高度。


我想做的是减少字体如果需要,大小仍然适合标签区域。

这部分工作

I have a label size W = Width & H = Height. It initially has a caption of say 30 letters in 4 words, each word separated by either a space or a line feed. Initially the label is about the right size for the caption in the selected font.

Using VBA, I now want to change the caption to say 45 letters in 5 words.
Using the late Stephen Leban?s fTextWidthOrHeight routine, I can get the width and height of new wording in the same font.

What I want to do is reduce the font size if necessary so that it still fits in the label area.
This partially works

展开 | 选择 | 换行 | 行号

推荐答案

嗨菲尔。


据推测,起始字体大小至少适合两行字体大小8?会更大吗?如果你知道它的字体大小从处理只有一行变为允许两行,那么可以将其设置为常量并检查。


我怀疑是否需要换行。当在标题中使用多个单词时,这些单词太窄而无法在一行上显示所有单词,那么它会自动换行。
Hi Phil.

Presumably the starting font size is such that it will fit at least two lines of font size 8? Will it be larger? If you know the font size where it changes from handling only one line to allowing two then that could be set as a constant and checked for.

I doubt line feeds will be required. When multiple words are used in a Caption which is too narrow to show all on one line then it wraps automatically.


实际上,没有


最初说字体大小是12(在我这个年纪我喜欢大字体)

标签在高度和宽度的组合中至少足够大以容纳初始30个字母标题。


我不能改变标签的大小,因为它可能与表单或报表上的其他控件重叠,所以我的想法是逐渐减小字体大小,直到它适合。


如果字体大小减小,不仅宽度减小,而且高度减小,因此我们可能会遇到字体大小减少1的情况,线路仍然太长,但是现在,随着字体高度的减小,有足够的空间使用2条线而不是最初的单线。


我知道这是去的很难。


我写了一些代码工作,但它是意大利面条代码,我对它没有信心。


我的补充是Sub ShrinkFont(Ctl As Control)
Actually, no

Initially say the font size is 12 (At my age I like a big font)
The label is a at least big enough in a combination of height and width to accommodate the initial 30 letter caption.

I can''t change the size of the label because it may overlap other controls on the form or report, so my thought is to progressively reduce the font size until it fits.

Mow as the font size reduces, not only does the width reduce, but also the height, so we may get the situation where the font size has been reduced by 1, the line is still too long, but now, with the reduced height of the font, there is enough room to use 2 lines rather than the initial single line.

I knew this was going to be tough one.

I have written some code that seems to work, but it is spaghetti code and I have little confidence in it.

My addition is the Sub ShrinkFont(Ctl As Control)
展开 | 选择 | Wrap | 行号


Phil ,在此场景中可以使用一个非常有用的Access报告属性,名为 TextWidth 。逻辑如下:
Phil, there is a very useful Property of an Access Report that can be used in this scenario called TextWidth. The Logic is as follows:
  1. 使用基本字符串计算字符的平均宽度,给定用于报告的坐标系中的特定字体名称和字体大小(在这种情况下为英寸)。
  2. 以英寸为单位确定标签控制的长度(在本例中为7.9167)。
  3. 以隐藏模式打开报告并将所需的代码放入详细信息''打印()事件。
  4. 循环通过所需的字体大小范围(在本例中为24到8)。
  5. 在第一个实例中(平均字符长度) * Len(测试字符串))< 7.9167(标签长度),这是可用于宽度为7.9167的标签的最大字体大小。我的结果是Tahoma字体的最大字体大小,可以用于7.9167英寸宽的标签,测试字符串是18。
  6. 这不能解决高度调整,我会把它留下来
  7. 如果您对此方法感兴趣,我会向您发送演示。
  8. 结果并不完美,因为实际上可以使用20的字体大小在这种情况下,关闭但没有雪茄! (LOL)。


这篇关于更改字体大小以适合标签尺寸。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆