Managed WebBrowser Control Sample
This sample demonstrates how to embed the WebBrowser control in a Windows Forms application to provide Web browsing capabilities or to display local HTML files. The sample also demonstrates how to enable interaction between your HTML scripts and your application code.
For information about using the samples, see the following topics:
Security Note: |
---|
This sample code is provided to illustrate a concept and should not be used in applications or Web sites, as it may not illustrate the safest coding practices. Microsoft assumes no liability for incidental or consequential damages should the sample code be used for purposes other than as intended. |
To build and run the sample using the command prompt
At the command prompt, navigate to the location where you saved the uncompressed sample files.
Navigate to one of the language-specific subdirectories under the ManagedWebBrowserSample directory.
Type msbuild to build the sample using the solution (.sln) file provided.
Type cd ManagedWebBrowser\bin\Debug to navigate to the location of the executable file.
Type ManagedWebBrowser.exe to run the sample.
To build and run the sample using Visual Studio
In Windows Explorer, navigate to the location where you saved the uncompressed sample files.
Navigate to one of the language-specific subdirectories under the ManagedWebBrowserSample directory.
Double-click the solution (.sln) file to open it in Visual Studio.
In Visual Studio, press F5 to build and run the sample.
To use the ManagedWebBrowser Sample
Type a URL such as https://www.microsoft.com into the text box and then click the arrow next to the text box.
Use the ToolStrip buttons to perform standard Web browser navigation.
Type the name of a file in the Filename text box, or click Browse and then select an HTML file from the folder browser.
Click the Load Script button, enter your name in the text box on the Web page, and then click the displayed link.
The form will display a message that contains the text you provided in the Web page.
Demonstrates
Using the WebBrowser control to provide Web browsing functionality.
Displaying a local HTML file in your form.
Calling methods in your application code from script code in your Web page.