Microsoft KB Archive/311303

= WebOCHostVB.exe Hosts the WebBrowser Control in Visual Basic .NET =

Article ID: 311303

Article Last Modified on 8/5/2004

-

APPLIES TO


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

-



This article was previously published under Q311303



SUMMARY
The WebOCHostVB.exe sample demonstrates how to host the WebBrowser control in Visual Basic .NET.



MORE INFORMATION
The following file is available for download from the Microsoft Download Center:

Download WebOCHostVB.exe now

Release Date: April 1, 2002

For additional information about how to download Microsoft Support files, click the following article number to view the article in the Microsoft Knowledge Base:

119591 How to Obtain Microsoft Support Files from Online Services

Microsoft scanned this file for viruses. Microsoft used the most current virus-detection software that was available on the date that the file was posted. The file is stored on security-enhanced servers that help to prevent any unauthorized changes to the file. The WebOCHostVB.exe file contains the following files:

WebOCHostVB.exe implements a Single Document Interface (SDI) application that enables Web browsing through the Internet Explorer WebBrowser control. The code in this sample uses a modular design wherein the WebBrowser is encapsulated in a custom Windows Forms UserControl, which in turn is hosted on the main form of your SDI application. You can then encapsulate some of the lengthy Internet Explorer command syntax and reuse the WebBrowser control in other forms in this project and other projects.

For example, the WebOCHostVB.exe sample reduces the method call to copy text from the WebBrowser control from webBrowser.ExecWB(SHDocVw.OLECMDID.OLECMDID_COPY, SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER) to: webOCWrapper.Copy The WebOCHostVB.exe sample demonstrates the following techniques:  How to browse by means of an address bar or by means of a custom Open dialog box that permits documents to be loaded both from a URL and from the local file system. How to implement simple editing commands (such as cut, copy, and paste) and how to receive notification of their status through the CommandStateChange event of the WebBrowser control. How to persist typed URLs in the address bar. The sample mimics the Internet Explorer combo box address bar with a simple test in the DWebBrowserEvents2::NavigateComplete2 event handler. The URL that a user types in the address bar is often not the final URL because either the user types a partial URL (such as www.microsoft.com instead of http://www.microsoft.com ) or because the server issues an HTTP redirect to another file. Therefore, this sample waits until the WebBrowser control throws the NavigateComplete2 event to guarantee the final, canonical form of the URL for the current page.

This samples uses the KeyDown event handler to set a Boolean value, wasUrlTyped, whenever the user types a URL. If this value is true inside the NavigateComplete2 event handler, the URL is added as a list item to the sorted combo box. How to implement the Find, the View Source, and the Internet Options Internet Explorer menu commands. To do this, the sample implements a COM interop declaration for IOleCommandTarget.For additional information, click the article number below to view the article in the Microsoft Knowledge Base:

311288 HOW TO: Invoke the Find, View Source, and Options Dialog Boxes for the WebBrowser Control from Visual Basic .NET

  How to print. The WebBrowser host control in this sample defines two overloaded Print methods: Public Sub Print(ByVal doUI As Boolean) Public Sub Print(ByVal tmplPath As String) Overloaded methods are a feature of object-oriented languages, such as Visual C# and Visual Basic, that support multiple definitions of a method if that the methods differ in the numbers and/or types of their parameters. (The cardinality and the type of a method's parameters is commonly called its signature).

In this case, the Print(Boolean) method prints a document that is hosted in a WebBrowser. This method may or may not display a dialog box, depending on the parameter. The Print(String) method prints a document and does not display a dialog box. This method uses a Microsoft Hypertext Markup Language (MSHTML) print template to automatically control print options such as paper size, orientation, and number of copies. 

Additional query words: WebOCHostVB

Keywords: kbdownload kbfile kbinfo KB311303

-

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

© Microsoft Corporation. All rights reserved.