vba 如何将 Excel 标签标题中的文本垂直居中?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6859127/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I vertically center the text in an Excel label's caption?
提问by phan
In Excel 2007, I inserted an ActiveX label onto my worksheet. I right-clicked on it and viewed Properties and managed to change the TextAlign property to 2 (frmTextAlignCenter).
在 Excel 2007 中,我在工作表中插入了一个 ActiveX 标签。我右键单击它并查看属性并设法将 TextAlign 属性更改为 2 (frmTextAlignCenter)。
This aligns the label caption's text to the center of the label (horizontally), but the text remains at the TOP of the label. How do I center the caption's text VERTICALLY so that it is in the smack middle of the label?
这会将标签标题的文本与标签的中心(水平)对齐,但文本仍位于标签的顶部。如何将标题的文本垂直居中,使其位于标签的中间?
I've searched "vertical alignment" in SO but nothing comes up for how to do this for an Excel label's caption.
我在 SO 中搜索了“垂直对齐”,但没有任何关于如何为 Excel 标签的标题执行此操作的信息。
Thanks!
谢谢!
采纳答案by jonsca
回答by Larv
There is a trick to do it with a single label. Add an transparent gif image of 1x1 pixel and set the PictureAlignment property to PicturePositionLeftCenter.
有一个技巧可以使用单个标签来做到这一点。添加一个 1x1 像素的透明 gif 图像并将 PictureAlignment 属性设置为 PicturePositionLeftCenter。
回答by YosiN
You will have to use 2 Labels.
您将不得不使用 2 个标签。
For Example, Call them LabelBack, LabelFront. The LabelFront should be set to Opaque and No-Border Make the height of LabelFront smaller than that of LabelBack and put it over it more or less.
例如,将它们称为 LabelBack、LabelFront。LabelFront 应该设置为 Opaque 和 No-Border 使 LabelFront 的高度小于 LabelBack 的高度,并或多或少地放在上面。
Then add the following code:
然后添加以下代码:
LabelFront.Top = (LabelBack.Top + (LabelBack.Height - LabelFront.Height) / 2) - 1
Notice, I subtracted 1
to compensate the 1
extra pixel within the LabelFront.
请注意,我减去1
以补偿1
LabelFront 内的额外像素。