Microsoft KB Archive/311280

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

Article ID: 311280

Article Last Modified on 7/15/2004

-

APPLIES TO


 * Microsoft Visual Basic .NET 2002 Standard Edition
 * Microsoft Visual Basic .NET 2003 Standard Edition
 * Microsoft Internet Explorer 5.5
 * Microsoft Internet Explorer (Programming) 6.0

-



This article was previously published under Q311280



For a Microsoft Visual C# .NET version of this article, see 313723.



For a Microsoft Visual Basic 6.0 version of this article, see 236777.

IMPORTANT: This article contains information about modifying the registry. Before you modify the registry, make sure to back it up and make sure that you understand how to restore the registry if a problem occurs. For information about how to back up, restore, and edit the registry, click the following article number to view the article in the Microsoft Knowledge Base:

256986 Description of the Microsoft Windows Registry

IN THIS TASK
SUMMARY
 * Description of the Technique
 * Visual Basic .NET Code to Modify Registry Key



SUMMARY
This article describes 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:  Internet Explorer tries to obtain the values from the following registry key:

HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\PageSetup

 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

 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 Basic .NET Code to Modify Registry Key
WARNING: If you use Registry Editor incorrectly, you may cause serious problems that may require you to reinstall your operating system. Microsoft cannot guarantee that you can solve problems that result from using Registry Editor incorrectly. Use Registry Editor at your own risk.

This sample Visual Basic .NET code illustrates how to modify the required registry key: Imports Microsoft.Win32 Imports System '........................ Public Sub SetIEFooter Dim strKey As String = &quot;Software\Microsoft\Internet Explorer\PageSetup&quot; Dim bolWritable As Boolean = True Dim strName As String = &quot;footer&quot; Dim oValue As Object = &quot;My New Footer&quot; Dim oKey As RegistryKey = Registry.CurrentUser.OpenSubKey(strKey, bolWritable) oKey.SetValue(strName, oValue) oKey.Close

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

back to the top

Keywords: kbhowtomaster kbregistry KB311280

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.