WebKit .NET

Tutorial - The Basics

Adding the Code

Double-click the Go! button to create a Click event handler and open the code view. Add the following code which causes the WebKitBrowser to navigate to the Url in our textbox when the button is clicked:

private void button1_Click(object sender, EventArgs e) { webKitBrowser1.Navigate(textBox1.Text); }

In the constructor for Form1, add the following code to create handlers for the form load and browser navigation events:

public Form1() { InitializeComponent(); this.Load += new EventHandler(Form1_Load); this.webKitBrowser1.Navigated += new WebBrowserNavigatedEventHandler(webKitBrowser1_Navigated); }

Add the following event handlers. When the form is loaded, we set the browser to display an obligitory 'Hello World' message. When the browser navigates to a new page, we update the contents of the textbox to reflect the new location:

void Form1_Load(object sender, EventArgs e) { webKitBrowser1.DocumentText = "<h1><a href=\"http://google.com\">Hello, World!</a></h1>"; } void webKitBrowser1_Navigated(object sender, WebBrowserNavigatedEventArgs e) { textBox1.Text = webKitBrowser1.Url.ToString(); }