Using the .NET WebBrowser Control in a WinForms project

Very easy to do. Just execute the following steps: 1. Create a new WinForms Project webbrowser1 2. Add the WebBrowser control from the ToolBox. Select View > ToolBox. Select WebBrowser in the Common Controls: webbrowser2 3. Drag the WebBroswer control on to your form Like so: webbrowser3 4. Add Event handling methods. Add an event for the form loaded: webbrowser5 5. Update the event handling code In Form.cs updates as follows. I have also included the option to apply zooming to the selected web page: [code language="csharp"] using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace WebBrowser { public partial class Form1 : Form { public Form1() { InitializeComponent(); webBrowser1.Navigate("www.google.co.uk"); } private void Form1_Load(object sender, EventArgs e) { if (webBrowser1.Document == null) return; if (webBrowser1.Document.Body != null) webBrowser1.Document.Body.Style = "zoom:90%;"; } } } [/code] 6. Run the application:

Comments

Popular posts from this blog

Using the Supervisor Controller Pattern to access View controls in MVVM

Getting started with Tesseract optical character recognition (OCR) library in Visual Studio

How to send an e-mail via Google SMTP using C#