C# 如何使用WebBrowser控件打印css应用的背景图像
我在winforms中使用webbrowser控件,现在发现我用css应用的背景图像不包括在打印输出中 有没有办法让webbrowser也打印所显示文档的背景 编辑: 因为我想通过编程来实现这一点,所以我选择了以下解决方案:C# 如何使用WebBrowser控件打印css应用的背景图像,c#,.net,printing,registry,webbrowser-control,C#,.net,Printing,Registry,Webbrowser Control,我在winforms中使用webbrowser控件,现在发现我用css应用的背景图像不包括在打印输出中 有没有办法让webbrowser也打印所显示文档的背景 编辑: 因为我想通过编程来实现这一点,所以我选择了以下解决方案: using Microsoft.Win32; ... RegistryKey regKey = Registry.CurrentUser .OpenSubKey("Software") .O
using Microsoft.Win32;
...
RegistryKey regKey = Registry.CurrentUser
.OpenSubKey("Software")
.OpenSubKey("Microsoft")
.OpenSubKey("Internet Explorer")
.OpenSubKey("Main");
//Get the current setting so that we can revert it after printjob
var defaultValue = regKey.GetValue("Print_Background");
regKey.SetValue("Print_Background", "yes");
//Do the printing
//Revert the registry key to the original value
regKey.SetValue("Print_Background", defaultValue);
另一种处理方法可能是读取值,并通知用户在打印前自行调整。我必须同意,像这样调整注册表不是一个好的做法,所以我愿意接受任何建议
感谢您的所有反馈默认情况下,浏览器根本不打印背景图像 在Firefox中
* File > Page Setup > Check Off "Print Background"
* File > Print Preview
在IE中
在歌剧中
* File > Print Options > Check Off "Print Page Background"
* File > Print Preview (You may have to scroll down/up to see it refresh)
如果要更改一个重要的系统设置,请确保首先读取当前设置,然后在完成后将其还原 我一开始就认为这是非常糟糕的做法,但如果你必须这样做,那就仁慈些。
Registry.LocalMachine
另外,尝试更改
LocalUser
而不是LocalMachine
——这样,如果你的应用程序崩溃(而且会崩溃),那么你只会让用户感到困惑,而不是让所有使用机器的人感到困惑。此设置对应的HKCU键是:
HKEY\U CURRENT\U USER\Software\Microsoft\Internet Explorer\Main\Print\u Background另一个注册表项是:
var sh = new ActiveXObject("WScript.Shell");
key = "HKEY_CURRENT_USER\\Software\\Microsoft\\Internet Explorer\\Main\\Print_Background";
var defaultValue = sh.RegRead(key);
sh.RegWrite(key,"yes","REG_SZ");
document.frames['detailFrame'].focus();
document.frames['detailFrame'].print();
sh.RegWrite(key,defaultValue,"REG_SZ");
return false;
HKEY\ U当前\用户\软件\ Microsoft\Internet Explorer\PageSetup\Print\后台
HKEY_LOCAL_MACHINE\Software\Microsoft\Internet Explorer\PageSetup\Print_Background为什么这是一种非常糟糕的做法?
var sh = new ActiveXObject("WScript.Shell");
key = "HKEY_CURRENT_USER\\Software\\Microsoft\\Internet Explorer\\Main\\Print_Background";
var defaultValue = sh.RegRead(key);
sh.RegWrite(key,"yes","REG_SZ");
document.frames['detailFrame'].focus();
document.frames['detailFrame'].print();
sh.RegWrite(key,defaultValue,"REG_SZ");
return false;