{"id":2694,"date":"2022-08-30T15:27:00","date_gmt":"2022-08-30T15:27:00","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/02\/06\/how-to-print-css-applied-background-images-with-webbrowser-control-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:27:00","modified_gmt":"2022-08-30T15:27:00","slug":"how-to-print-css-applied-background-images-with-webbrowser-control-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/how-to-print-css-applied-background-images-with-webbrowser-control-collection-of-common-programming-errors\/","title":{"rendered":"How to print css applied background images with WebBrowser control-Collection of common programming errors"},"content":{"rendered":"<p>I am using the webbrowser control in winforms and discovered now that background images which I apply with css are not included in the printouts.<\/p>\n<p>Is there a way to make the webbrowser print the background of the displayed document too?<\/p>\n<p>Edit: Since I wanted to do this programatically, I opted for this solution:<\/p>\n<pre><code>using Microsoft.Win32;\n\n...\n\nRegistryKey regKey = Registry.CurrentUser\n                    .OpenSubKey(\"Software\")\n                    .OpenSubKey(\"Microsoft\")\n                    .OpenSubKey(\"Internet Explorer\")\n                    .OpenSubKey(\"Main\");\n\n\/\/Get the current setting so that we can revert it after printjob\nvar defaultValue = regKey.GetValue(\"Print_Background\");\nregKey.SetValue(\"Print_Background\", \"yes\");\n\n\/\/Do the printing\n\n\/\/Revert the registry key to the original value\nregKey.SetValue(\"Print_Background\", defaultValue);\n<\/code><\/pre>\n<p>Another way to handle this might be to just read the value, and notify the user to adjust this himself before printing. I have to agree that tweaking with the registry like this is not a good practice, so I am open for any suggestions.<\/p>\n<p>Thanks for all your feedback<\/p>\n<ol>\n<li>\n<p>If you&#8217;re going to go and change an important system setting, make sure to first read the current setting and restore it when you are done.<\/p>\n<p>I consider this <em>very bad<\/em> practice in the first place, but if you must do it then be kind.<\/p>\n<pre><code>Registry.LocalMachine\n<\/code><\/pre>\n<p>Also, try changing <code>LocalUser<\/code> instead of <code>LocalMachine<\/code> &#8211; that way if your app crashes (and it will), then you&#8217;ll only confounded the user, not everyone who uses the machine.<\/p>\n<\/li>\n<li>\n<p>The corresponding HKCU key for this setting is: HKEY_CURRENT_USER\\Software\\Microsoft\\Internet Explorer\\Main\\Print_Background<\/p>\n<\/li>\n<li>\n<p>Another registry key would be : HKEY_CURRENT_USER\\Software\\Microsoft\\Internet Explorer\\PageSetup\\Print_Background HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Internet Explorer\\PageSetup\\Print_Background<\/p>\n<\/li>\n<li>\n<p>By default, the browser does not print background images at all.<\/p>\n<p>In Firefox<\/p>\n<pre><code>* File &gt; Page Setup &gt; Check Off \"Print Background\"\n* File &gt; Print Preview\n<\/code><\/pre>\n<p>In IE<\/p>\n<pre><code>* Tools &gt; Internet Options &gt; Advanced &gt; Printing\n* Check Off \"Print Background Images and Colors\"\n<\/code><\/pre>\n<p>In Opera<\/p>\n<pre><code>* File &gt; Print Options &gt; Check Off \"Print Page Background\"\n* File &gt; Print Preview (You may have to scroll down\/up to see it refresh)\n<\/code><\/pre>\n<\/li>\n<li>\n<pre><code>var sh = new ActiveXObject(\"WScript.Shell\");\nkey = \"HKEY_CURRENT_USER\\\\Software\\\\Microsoft\\\\Internet Explorer\\\\Main\\\\Print_Background\";\nvar defaultValue = sh.RegRead(key); \nsh.RegWrite(key,\"yes\",\"REG_SZ\");\ndocument.frames['detailFrame'].focus(); \ndocument.frames['detailFrame'].print();\nsh.RegWrite(key,defaultValue,\"REG_SZ\");  \nreturn false; \n<\/code><\/pre>\n<\/li>\n<\/ol>\n<p id=\"rop\"><small>Originally posted 2014-02-06 04:20:05. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>I am using the webbrowser control in winforms and discovered now that background images which I apply with css are not included in the printouts. Is there a way to make the webbrowser print the background of the displayed document too? Edit: Since I wanted to do this programatically, I opted for this solution: using [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2694","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2694","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=2694"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2694\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=2694"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=2694"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=2694"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}