Membuat Web Browser menggunakan WPF

Posted: March 20, 2013 by Nila Novita Sari in Uncategorized

1. Buat projet baru menggunakan WPF

                                    perlu1

 

2. Design tampilan UI pada xaml nya, terdiri dari 3 buah button, untuk go , back dan forward , dan sebuah web browser.

                                    perlu2

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WPFWebControl
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}

private void Window_Loaded(object sender, RoutedEventArgs e)
{
try
{
//If You Want to define a defualt URI then you can define like below…
MyWebBrowser.Source = new Uri(“http://www.c-sharpcorner.com&#8221;);

//Otherwise for blank you can set it as like below…
//MyWebBrowser.Source = new Uri(“about:blank”);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}

private void MyBack_Click(object sender, RoutedEventArgs e)
{
try
{
MyWebBrowser.GoBack();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}

private void MyForward_Click(object sender, RoutedEventArgs e)
{
try
{
MyWebBrowser.GoForward();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}

private void MyGo_Click(object sender, RoutedEventArgs e)
{
try
{
MyWebBrowser.Source = new Uri(“http://facebook.com&#8221;);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}

private void MyWebBrowser_LoadCompleted(object sender, NavigationEventArgs e)
{
MessageBox.Show(“Completed.”);
}
}
}
                           perlu3

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s