Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

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


View products that this article applies to.

Summary

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

↑ Back to the top


More information

The following file is available for download from the Microsoft Download Center:
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:

File NameSize
About.resx7 KB
About.vb3 KB
AssemblyInfo.vb2 KB
Back.bmp2 KB
BM.ico766 bytes
Forward.bmp2 KB
Home.bmp406 bytes
MainForm.resx19 KB
MainForm.vb19 KB
OleCommandTarget.vb2 KB
OpenDialog.resx7 KB
OpenDialog.vb6 KB
WebOCHost.resources1 KB
WebOCHost.resx4 KB
WebOCHostCtrl.resx7 KB
WebOCHostCtrl.vb13 KB
WebOCHostVB.sln1 KB
WebOCHostVB.suo12 KB
WebOCHostVB.vbproj7 KB
WebOCHostVB.vbproj.user2 KB

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.

↑ Back to the top


Keywords: KB311303, kbinfo, kbfile, kbdownload, kbarchive, kbnosurvey

↑ Back to the top

Article Info
Article ID : 311303
Revision : 6
Created on : 2/28/2014
Published on : 2/28/2014
Exists online : False
Views : 414