Currency Converter In Windows Form Application Using WebBrowser

Thr first thing that you have to do is make a project from the Windows form application.

If you are not familiar with the desktop Application, then I recommend you read this blog. In this blog, you will learn to make a Windows form Application from scratch to the deployment.

Here, we are just going to make a simple online currency converter in a desktop Application.

To make an online currency converter, the things which you need in your Form1 page are given below.

  • One Button
  • Web Browser

You can easily drag and drop these from the toolbox. Go to Toolbox and drag a button and a Web Browser. Also, change the button text to “Open Currency Converter”.

Be sure that your page looks, as shown below.

 

This page contains a button and a Web Browser.

You can place a code at backend button onClick event.

  1. try {  
  2.     webBrowser1.Navigate("https://www.google.com/finance/converter");  
  3. catch (Exception) {  
  4.     MessageBox.Show("Internet Connection Needed");  
  5. }  

In this code, you can see that we insert a link to an online currency converter. When the user clicks on a button, then Web Browser is navigated to an online currency converter.

To use this currency converter, the user needs to have an internet connection because it is working online. If the user's internet is not working or a user is not connected to the internet, then the catch exception is called and it shows a message box, which contains a text of “Internet Connection Needed”.

Full code

  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.ComponentModel;  
  4. using System.Data;  
  5. using System.Drawing;  
  6. using System.Linq;  
  7. using System.Text;  
  8. using System.Threading.Tasks;  
  9. using System.Windows.Forms;  
  10. namespace CurrencyConverter {  
  11.     public partial class Form1: Form {  
  12.         public Form1() {  
  13.             InitializeComponent();  
  14.         }  
  15.         private void button1_Click(object sender, EventArgs e) {  
  16.             try {  
  17.                 webBrowser1.Navigate("https://www.google.com/finance/converter");  
  18.             } catch (Exception) {  
  19.                 MessageBox.Show("Internet Connection Needed");  
  20.             }  
  21.         }  
  22.         private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) {}  
  23.         private void Form4_Load(object sender, EventArgs e) {}  
  24.     }  
  25. }  

Code explanation

On button onClick event, a try catch block is placed. In Try block, Web Browser is navigated to the currency converter link. In catch block, a warning message is displayed.

While clicking on button a page is displayed, which is given below.

 

Now, you are able to use this currency converter and convert any currency which you want. This is quite helpful in your desktop Applications, where you don’t want to make you own logic and build your own currency converter.

X

Build smarter apps with Machine Learning, Bots, Cognitive Services - Start free.

Start Learning Now