简体   繁体   English

使用IHTMLDocument强制加粗

[英]Force bold with IHTMLDocument

I am using an HTML editing control build on MS HTML. 我正在使用基于MS HTML的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 谢谢IA

Yes, but pressing the bold switch would then function expectedly (if one knows). 是的,但是按粗体开关将可以正常工作(如果知道的话)。 Like in other editors. 就像在其他编辑器中一样。

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

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