从 WebBrowser 控件打印时删除 header 和页脚
Remove header and footer when printing from WebBrowser control
我有一个使用 MySql 数据库的 C# 应用程序。我使用 HTML.
构建了一个报告
我用标签填充字符串属性,并以新的形式将内容发送到 WebBrowser 控件。
报表显示正确,但是当我调用打印预览对话框时,
webBrowser1.ShowPrintPreviewDialog();
header 和页脚出现在报告中,其值为:
- 在 header 中:页数。
- 在页脚中:日期和“about:blank”。
这是问题的截图:
如何删除 header 和页脚?
看起来您可能必须在打印前更改注册表设置,然后再将它们改回来:
如何使用 Visual C# .NET 以编程方式更改 Internet Explorer 和 WebBrowser 控件的打印机设置
https://support.microsoft.com/en-us/kb/313723
using Microsoft.Win32;
//...............................
public void IESetupFooter()
{
string strKey = "Software\Microsoft\Internet Explorer\PageSetup";
bool bolWritable = true;
string strName = "footer";
object oValue = "Test Footer";
RegistryKey oKey = Registry.CurrentUser.OpenSubKey(strKey,bolWritable);
Console.Write (strKey);
oKey.SetValue(strName,oValue);
oKey.Close();
}
我有一个使用 MySql 数据库的 C# 应用程序。我使用 HTML.
构建了一个报告我用标签填充字符串属性,并以新的形式将内容发送到 WebBrowser 控件。
报表显示正确,但是当我调用打印预览对话框时,
webBrowser1.ShowPrintPreviewDialog();
header 和页脚出现在报告中,其值为:
- 在 header 中:页数。
- 在页脚中:日期和“about:blank”。
这是问题的截图:
如何删除 header 和页脚?
看起来您可能必须在打印前更改注册表设置,然后再将它们改回来:
如何使用 Visual C# .NET 以编程方式更改 Internet Explorer 和 WebBrowser 控件的打印机设置
https://support.microsoft.com/en-us/kb/313723
using Microsoft.Win32;
//...............................
public void IESetupFooter()
{
string strKey = "Software\Microsoft\Internet Explorer\PageSetup";
bool bolWritable = true;
string strName = "footer";
object oValue = "Test Footer";
RegistryKey oKey = Registry.CurrentUser.OpenSubKey(strKey,bolWritable);
Console.Write (strKey);
oKey.SetValue(strName,oValue);
oKey.Close();
}