Microsoft KB Archive/313723

From BetaArchive Wiki

Article ID: 313723

Article Last Modified on 5/4/2005



APPLIES TO

  • Microsoft Visual C# .NET 2002 Standard Edition
  • Microsoft Internet Explorer 5.5
  • Microsoft Internet Explorer (Programming) 6.0



This article was previously published under Q313723

Important This article contains information about how to modify the registry. Make sure to back up the registry before you modify it. Make sure that you know how to restore the registry if a problem occurs. For more information about how to back up, restore, and modify the registry, click the following article number to view the article in the Microsoft Knowledge Base:

256986 Description of the Microsoft Windows registry


For a Microsoft Visual Basic .NET version of this article, see 311280.

IN THIS TASK

SUMMARY

REFERENCES

SUMMARY

This step-by-step article shows you how to programmatically set the page margins, the header, and the footer for printing from Internet Explorer and the WebBrowser control.

back to the top

Description of the Technique

Users can easily change Internet Explorer printer settings for the page margins, the header, and the footer through the Internet Explorer user interface. However, Internet Explorer and the WebBrowser control do not include methods to change these settings programmatically.

NOTE: You cannot use the ExecWB command to set the page margins, the header, or the footer. These values are stored in the registry.

If you need to programmatically change the printer settings for Internet Explorer or the WebBrowser control, you can only change the page margins, the header information, and the footer information. You cannot programmatically change other settings such as the page orientation or the default printer.

The following steps outline how Microsoft Internet Explorer accesses the printer settings:

  1. Internet Explorer tries to obtain the values from the following registry key:

    HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\PageSetup

  2. If the key in step 1 does not exist, Internet Explorer tries to create this key by copying the values from the following key:

    HKEY_LOCAL_MACHINE\Software\Microsoft\Internet Explorer\PageSetup

  3. If the key in step 2 does not exist, default values are provided.

NOTE: These registry values are system-wide and affect all instances of the WebBrowser control and Internet Explorer for the current user.

back to the top

Visual C# .NET Code to Modify Registry Key

Warning Serious problems might occur if you modify the registry incorrectly by using Registry Editor or by using another method. These problems might require that you reinstall your operating system. Microsoft cannot guarantee that these problems can be solved. Modify the registry at your own risk.
This sample Visual C# .NET code illustrates how to modify the required registry key:

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


    }
                

NOTE: Your application must have read and write permissions for the registry key.

back to the top

REFERENCES

For additional information, click the article number below to view the article in the Microsoft Knowledge Base:

236777 How To Change Print Settings for Internet Explorer and WebBrowser Control Programmatically


back to the top


Additional query words: print settings

Keywords: kbhowto kbhowtomaster KB313723