网页浏览器通过代码控制页面设置选项
我有一个带有网络浏览器控件的.net 表单应用程序。我在控件中加载了一个 html 文件。 我想从代码本身设置边距、页眉和页脚以及方向来打印该文档...
webbrowser1.ShowPageSetupDialog()
webbrowsre1.print()
目前我通过调用 pagesetupDialog 手动设置这些。我如何从代码中设置所有必需的选项?
谢谢你!
I have a .net Forms Application with webbrowser control. I have a html file loaded in the control.
I want to set Margins, Headers and Footers and orientation from the code itself for printing that document...
webbrowser1.ShowPageSetupDialog()
webbrowsre1.print()
Currently I set these manually by calling the pagesetupDialog . How do i set these all the required options from code ?
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我上次检查时,网络浏览器控件的页眉和页脚实际上存储在注册表中。要更改它们,您只需更新注册表值即可。当然,这会影响IE,而不仅仅是网页浏览器控件。
密钥位于 Microsoft.Win32.Registry.CurrentUser 下:
“Software\Microsoft\Internet Explorer\PageSetup”
您可能希望在更改值之前缓存该值,以便在打印完成后可以将其更改回来。它并不优雅,如果有人有更优雅的解决方案,我很乐意提出,但似乎网络浏览器控件并不真正支持我们希望的所有功能。
The last I checked, headers and footers for the webbrowser control are actually stored in the registry. To change them, you can simply update the registry values. Of course, this will affect IE, not just the webbrowser control.
The key is under Microsoft.Win32.Registry.CurrentUser here:
"Software\Microsoft\Internet Explorer\PageSetup"
You might want to cache the value before you change it so you can change it back when you're done printing. It's not elegant and I'd love to head if anyone has a more elegant solution but it seems the webbrowser control doesn't really support all the features we would like it to.