使用 IHTMLDocument 强制加粗
我正在使用基于 MS HTML 构建的 HTML 编辑控件。
我需要能够强制文本加粗/取消加粗,但找不到一种简单的方法来做到这一点。
我可以按如下方式切换粗体状态:
(D as IHTMLDocument2).execCommand('Bold', False, EmptyParam);
我可以按如下方式获取粗体状态:
bIsBold := (D as IHTMLDocument2).queryCommandValue('Bold');
现在您当然会说,好吧,只需获取粗体状态,然后在需要时切换它。
不幸的是,所选文本实际上可以具有三种状态:非粗体/部分粗体/全粗体,因此我被迫在查询之前盲目地切换状态,以确保它仅处于两种已知状态:非粗体/全粗体。这很丑陋,所以我想知道我是否遗漏了一些明显的东西。
谢谢IA
I am using an HTML editing control build on MS HTML.
I need to be able to force text to be bold/unbold and cannot find an easy way to do this.
I can toggle bold status as follows:
(D as IHTMLDocument2).execCommand('Bold', False, EmptyParam);
I can get bold status as follows:
bIsBold := (D as IHTMLDocument2).queryCommandValue('Bold');
Now of course you will say, well duh, just get the bold status and then toggle it if you need to.
Unfortunately the selected text can actually have three states: not bold/partially bolded/all bold, so i am forced to blindly toggle the status before querying it to ensure it is only in the two know states: not bold/all bold. This is quite ugly so i would like to know if i am missing something obvious.
Thanks IA
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,但是按下粗体开关就会按预期运行(如果有人知道的话)。就像其他编辑器一样。
Yes, but pressing the bold switch would then function expectedly (if one knows). Like in other editors.