WPF Webrowser control in VB.NET

In this article we will learn how to use WebBrowser control in WPF using VB.NET.
  • 5133

In this article we will learn how to use WebBrowser control in WPF using VB.NET.

WebBrowser control

we can use WebBrowser control to show html document within our WPF application.

XAML code

<Window x:Class="MainWindow"

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    Title="MainWindow" Height="350" Width="525">

    <Grid Height="431" Width="611">

        <Grid.ColumnDefinitions>

            <ColumnDefinition Width="231*" />

            <ColumnDefinition Width="272*" />

        </Grid.ColumnDefinitions>

        <WebBrowser Height="248" HorizontalAlignment="Left" Name="WebBrowser1" VerticalAlignment="Top" Width="503" Margin="0,12,0,0" Grid.ColumnSpan="2" />

        <Button Content="Forward" Height="23" HorizontalAlignment="Left" Margin="190,276,0,0" Name="Button1" VerticalAlignment="Top" Width="75" Grid.ColumnSpan="2" />

    </Grid>

</Window>

 

The form looks like this.

bw1.gif
 

figure 1.

Navigate method on WebBrowser control is used to load the site in the control.

Now double click on the forward Button it will navigate to http://www.c-sharpcorner.com.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Button1.Click

        WebBrowser1.Navigate(New Uri("http://www.c-sharpcorner.com"))

    End Sub

 

    Private Sub Window_Loaded(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles MyBase.Loaded

        WebBrowser1.Navigate(New Uri("http://www.google.com"))

    End Sub

 

Now run the application and test it. I have made google.com as default web site to be loaded.


 

bw2.gif 


Figure 2.

 

Now click on the Button forward.
 

bw3.gif 


Figure 3.

Categories

More Articles

© 2019 DotNetHeaven. All rights reserved.