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.
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.
- try {
- webBrowser1.Navigate("https://www.google.com/finance/converter");
- } catch (Exception) {
- MessageBox.Show("Internet Connection Needed");
- }
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
- 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 CurrencyConverter {
- public partial class Form1: Form {
- public Form1() {
- InitializeComponent();
- }
- private void button1_Click(object sender, EventArgs e) {
- try {
- webBrowser1.Navigate("https://www.google.com/finance/converter");
- } catch (Exception) {
- MessageBox.Show("Internet Connection Needed");
- }
- }
- private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) {}
- private void Form4_Load(object sender, EventArgs e) {}
- }
- }
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.