Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/319.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打印的注册表项_C#_Winforms_Printing_Registry_Webbrowser Control - Fatal编程技术网

C# 无法修改WebBrowser打印的注册表项

C# 无法修改WebBrowser打印的注册表项,c#,winforms,printing,registry,webbrowser-control,C#,Winforms,Printing,Registry,Webbrowser Control,我使用以下代码从WebBrowser打印不带页眉和页脚的文档: string keyName = @"Software\Microsoft\Internet Explorer\PageSetup"; using (RegistryKey key = Registry.CurrentUser.OpenSubKey(keyName, true)) { if (key != null) {

我使用以下代码从WebBrowser打印不带页眉和页脚的文档:

string keyName = @"Software\Microsoft\Internet Explorer\PageSetup";
            using (RegistryKey key = Registry.CurrentUser.OpenSubKey(keyName, true))
            {
                if (key != null)
                {
                    string old_footer = key.GetValue("footer").ToString();
                    string old_header = key.GetValue("header").ToString();
                    key.SetValue("footer", "");
                    key.SetValue("header", "");
                    md_preview.ShowPrintDialog();
                    key.SetValue("footer", old_footer);
                    key.SetValue("header", old_header);
                }
            }

我也在
使用Microsoft.Win32。但是,当我尝试打印时,仍然会在打印的页面上看到页眉和页脚。

ShowPrintDialog()是否仅在打印完成后返回?如果调用没有阻止执行,用户会看到打印对话框,代码会立即恢复旧值。@Alexazzariol我如何阻止执行?我对WinForms和C#比较陌生。这是WebBrowser控件无法做到的。如果在打印前确实需要显示“打印”对话框,则无法获得打印作业已排队的通知,因此可以重置页脚/页眉设置。您可以改为使用Print()方法,然后可以安全地重置页脚/页眉设置,但用户将无法选择打印机(或对默认打印设置进行任何其他更改)。