Remove header and footer when printing from WebBrowser control

8k views Asked by At

I have a C# application that use MySql database. I built a report using HTML.

I fill string attribute with tags and send the content to a WebBrowser control in a new form.

The report appear correctly, but when I call print preview dialog,

webBrowser1.ShowPrintPreviewDialog();

the header and footer appear in the report with values:

  • In header: # of pages.
  • In footer: Date and "about:blank".

This is a screenshot for the issue:

enter image description here

How could I remove the header and footer?

1

There are 1 answers

4
WraithNath On BEST ANSWER

Looks like you may have to change registry settings before printing, then change them back again:

How To Programmatically Change Printer Settings for Internet Explorer and WebBrowser Control by Using Visual C# .NET

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

enter image description here