Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/316.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使用WebBrowser控件打印css应用的背景图像_C#_.net_Printing_Registry_Webbrowser Control - Fatal编程技术网

C# 如何使用WebBrowser控件打印css应用的背景图像

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

我在winforms中使用webbrowser控件,现在发现我用css应用的背景图像不包括在打印输出中

有没有办法让webbrowser也打印所显示文档的背景

编辑: 因为我想通过编程来实现这一点,所以我选择了以下解决方案:

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;