2008-09-07 64 views
3

我在winforms中使用webbrowser控件,現在發現我用css應用的背景圖像不包含在打印輸出中。如何使用WebBrowser控件打印css應用的背景圖像

有沒有辦法讓網頁瀏覽器打印顯示文檔的背景呢?

編輯: 因爲我想以編程方式做到這一點,我選擇了這個解決方案:

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); 

另一種方式來處理,這可能是剛讀值,並通知用戶之前調整這個自己打印。我必須同意,像這樣調整註冊表並不是一個好的做法,所以我願意接受任何建議。

感謝您的反饋

回答

1

如果你打算去改的一項重要制度設置,請務必先閱讀當前設置並在完成後恢復。

我認爲這個很糟糕練習首先,但如果你必須這樣做,那麼會友好。如果你的應用程序崩潰這種方式(它會),那麼你只會混淆的用戶,而不是大家誰使用機器 -

Registry.LocalMachine 

另外,嘗試改變​​代替LocalMachine

0

默認情況下,瀏覽器根本不打印背景圖像。

在Firefox

* File > Page Setup > Check Off "Print Background" 
* File > Print Preview 

在IE

* Tools > Internet Options > Advanced > Printing 
* Check Off "Print Background Images and Colors" 

在Opera

* File > Print Options > Check Off "Print Page Background" 
* File > Print Preview (You may have to scroll down/up to see it refresh) 
1

此設置的相應的HKCU關鍵是: HKEY_CURRENT_USER \軟件\微軟\的Internet Explorer \ MAIN \ Print_Background

2

另一個註冊表項是: HKEY_CURRENT_USER \軟件\微軟\的Internet Explorer \ PAGESETUP \ Print_Background HKEY_LOCAL_MACHINE \ Software \ Microsoft \ Internet Explorer \ PageSetup \ Print_Background

0
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;