简体   繁体   English

如何在Windows小工具中将g:文本样式设置为粗体字体?

[英]How to set g:text style to bold font in a Windows Gadget?

I'm developing a Vista/Win7 Desktop Gadget that uses a translucent g:background ( doc ) area with g:text ( doc ) on top. 我正在开发一个Vista / Win7桌面小工具,它使用半透明的g:backgrounddoc )区域,顶部是g:textdoc )。 I'm adding the text via addTextObject ( doc ), and this all works as expected. 我正在通过addTextObjectdoc )添加文本,这一切都按预期工作。

However, I can't figure out how to set that text to bold style. 但是,我无法弄清楚如何将该文本设置为粗体样式。 There doesn't seem to be a way to do this directly via the exposed properties that I can see, and I can't use regular text + CSS in this case due to the fact this text is placed onto a g:background object. 似乎没有办法通过我可以看到的暴露属性直接执行此操作,并且在这种情况下我不能使用常规文本+ CSS,因为此文本被放置在g:background对象上。

I have also tried specifying a bold font directly, such as Arial Bold (doesn't work) instead of Arial (works). 我也尝试直接指定粗体字体,例如Arial Bold (不起作用)而不是Arial (作品)。

So how can this be done? 那么怎么做呢?

Edit : I have tried setting font-weight:bold for both the body and the g:background object that parents my text; 编辑 :我已经尝试为body和g:background对象设置font-weight:bold ; no luck. 没运气。

See Flip Calendar , by Jonathan Abbott. 请参阅乔纳森·阿博特的翻转日历 His code is usually well commented so maybe you can get some ideas from that. 他的代码通常都有很好的评论,所以也许你可以从中获得一些想法。

EDIT 编辑
The source of my information was from the early days of Vista Beta 2 where that was the official word from MS. 我的信息来源是Vista Beta 2的早期版本,这是MS的官方消息。 I also found the following response to a thread on the MSDN forums regarding the Flip Calendar gadget itself: 我还在MSDN论坛上找到了关于Flip Calendar小工具本身的以下响应:

http://social.msdn.microsoft.com/Forums/en-US/sidebargadfetdevelopment/thread/841e9d5e-32e9-453f-bd0e-dc5a4e607c33/ http://social.msdn.microsoft.com/Forums/en-US/sidebargadfetdevelopment/thread/841e9d5e-32e9-453f-bd0e-dc5a4e607c33/

The gadget has options for setting bold font on the day of the month (ag:text object) but on closer inspection it doesn't work. 该小工具可以选择在月份的某一天设置粗体字体(ag:文本对象),但仔细检查它就不起作用。 Sorry about that. 对于那个很抱歉。 The MS guys have been known to be wrong as well on one or more occasions. 在一次或多次情况下,MS人员也被认为是错误的。 I can honestly say that I don't use the g:text object. 我可以诚实地说我不使用g:text对象。

This means your only (well, non activex route) option is VML text, which provides a lot of flexibility on layout. 这意味着您唯一的(好的,非activex路由)选项是VML文本,这为布局提供了很大的灵活性。 However, you will have to place it on a fully opaque area of the gadget which is probably why you wanted to use the addTextObject in the first place. 但是,您必须将它放在小工具的完全不透明区域,这可能是您想要首先使用addTextObject的原因。 Gary Beene's site really helped me out when I was getting started, but it doesn't go into any detail on the v:textbox element and the v:textpath element , though the MSDN documentation goes into enough detail on these. 我开始时, Gary Beene的网站确实帮助了我,但它没有详细介绍v:textbox元素v:textpath元素 ,尽管MSDN文档详细介绍了这些内容。

If you need to place the text on a non-fully opaque area of the gadget, then you could still go the VML route and place an image behind the text that acts as a shadow, starting out fully opaque and fading to fully transparent. 如果您需要将文本放置在小工具的非完全不透明区域,那么您仍然可以使用VML路径并将图像放置在充当阴影的文本后面,从完全不透明开始并逐渐淡化为完全透明。 This is how Microsoft does text in window title bars with aero enabled. 这就是Microsoft在启用了aero的窗口标题栏中执行文本的方式。
Alternatively, you could create an ActiveXObject that draws the text you need in the font you want and saves the image to a temporary file in the gadget folder. 或者,您可以创建一个ActiveXObject,以所需的字体绘制所需的文本,并将图像保存到gadget文件夹中的临时文件中。 Then you set that to the src of an addImageObject. 然后将其设置为addImageObject的src。 I've done something similar in a gadget and it's fast enough not to be noticeable. 我在小工具中做过类似的事情,而且速度不够明显。 You can also set min/max dimensions so shrinking/stretching to fit becomes a breeze. 您还可以设置最小/最大尺寸,以便缩小/拉伸以适应变得轻而易举。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM