使用 IHTMLDocument 强制加粗

发布于 2025-01-03 06:16:29 字数 463 浏览 4 评论 0原文

我正在使用基于 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 技术交流群。

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

发布评论

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

评论(1

不必你懂 2025-01-10 06:16:29

是的,但是按下粗体开关就会按预期运行(如果有人知道的话)。就像其他编辑器一样。

Yes, but pressing the bold switch would then function expectedly (if one knows). Like in other editors.

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