简体   繁体   English

WebBrowser打印预览命令

[英]WebBrowser Print Preview Command

I'm just trying to get a print preview of an html document contained within a Web Browser control. 我只是想获取Web浏览器控件中包含的html文档的打印预览。 I'm successfully able to print the document being displayed using this code: 我可以使用以下代码成功打印正在显示的文档:

IHTMLDocument2 doc = WebBrowser.Document as IHTMLDocument2; doc.execCommand("Print", false, null);

I realize that there are other methods to print the document such as creating an xps document and then handing it the paginator, however this solution just seems very nice. 我意识到还有其他打印文档的方法,例如创建xps文档,然后将其交给分页器,但是这种解决方案看起来非常不错。

Now I'm just wondering why there isn't a similar command to do the same for displaying a print preview. 现在,我只是想知道为什么没有类似的命令可以显示打印预览。 I've looked at the list of command identifiers: https://msdn.microsoft.com/en-us/library/ms533049(v=vs.85).aspx and didn't manage to find a print preview command... or a print command haha, which makes me think I'm looking in the wrong place, although that list seemed to correspond with the object I'm using as those are the command identifiers for the execCommand function. 我已经查看了命令标识符的列表: https : //msdn.microsoft.com/zh-cn/library/ms533049(v=vs.85).aspx ,但是没有找到打印预览命令。 。或打印命令haha,这使我觉得我找错了地方,尽管该列表似乎与我使用的对象相对应,因为这些是execCommand函数的命令标识符。

The top answer to this question: Displaying Print Preview of HTML Document without DocumentViewer worked for me and I was successfully able to display a print preview. 这个问题的最高答案: 在没有DocumentViewer的情况下显示HTML文档的打印预览对我来说很有效,并且我能够成功显示打印预览。 However, the code is confusing and seems bloated. 但是,该代码令人困惑,并且看起来很肿。

Is there a way to display a print preview using the above method? 是否可以使用上述方法显示打印预览? Also, where is the actual list of commands for the execCommand function? 另外,execCommand函数的实际命令列表在哪里?

Thanks. 谢谢。

The complete list of command identifiers that's supported is documented here on MSDN . MSDN上记录受支持的命令标识符的完整列表。

The bit that's poorly documented is this is the list of command identifiers, not strings that execCommand uses. 文献不多的地方是命令标识符列表,而不是execCommand使用的字符串。 You're calling IDM_EXECPRINT , which is aliased as a string simply as "Print" . 您正在调用IDM_EXECPRINT ,该别名作为字符串的别名,简称为"Print" Most of the other strings are mapped to the command identifier just without the "IDM_" portion of the identifier. 其他大多数字符串仅在没有标识符的“ IDM_”部分的情况下映射到命令标识符。

As you can see from that list, there's no version of a print preview, so I'm afraid you'll need to find another solution. 从该列表中可以看到,没有打印预览的版本,因此,恐怕您需要找到其他解决方案。

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

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