Q:

how to print .htm files in c#?

I can't seem to find a good way to print .htm files in c# using .net 4.0, visual studio 2010 and windows forms. When i tried to print it directly, it printed the raw html data instead of printing the "page" itself.
The only way i know to print it, is to use a WebBrowser control.  When i print the document, it doesn't print colors and the page isn't printed correctly.  For example, the edges are not drawn and so on.
Code for Web Browser :
public void Print()
{
    // Create a WebBrowser instance. 
    WebBrowser webBrowserForPrinting = new WebBrowser();

    // Add an event handler that prints the document after it loads.
    webBrowserForPrinting.DocumentCompleted +=
        new WebBrowserDocumentCompletedEventHandler(PrintDocument);

    // Set the Url property to load the document.
    webBrowserForPrinting.Url = new Uri(Core.textLog);
}

private void PrintDocument(object sender, WebBrowserDocumentCompletedEventArgs e)
{
    ((WebBrowser)sender).ShowPrintDialog();
    //// Print the document now that it is fully loaded.
    //((WebBrowser)sender).Print();

    //// Dispose the WebBrowser now that the task is complete. 
    ((WebBrowser)sender).Dispose();
}

What can i do?
Thank you!

A:

Ok, as i said, problem was that edge are not drawn and neither are the backgrounds.
Here is how i solved it.
Hashtable values = new Hashtable();

values.Add("margin_left", "0.1");
values.Add("margin_right", "0.1");
values.Add("margin_top", "0.1");
values.Add("margin_bottom", "0.1");
values.Add("Print_Background", "yes");

using (RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Internet Explorer\PageSetup", true))
{
    if (key == null) return;

    foreach (DictionaryEntry item in values)
    {
        string value = (string)key.GetValue(item.Key.ToString());

        if (value != item.Value.ToString())
        {
            key.SetValue(item.Key.ToString(), item.Value);
        }
    }
}

So before i print, i go to regedit, change the values, and the document gets printed perfectly. Hope this helps other people that have the same problem when printing from webbrowser control in windows forms.

