C# - Simple Conversion Application

In this tutorial we will create a Simple Conversion Application using C#. This application is consist of different functionalities that can be used at some point. C# is a general-purpose, object-oriented programming language. C# automatically manages inaccessible object memory using a garbage collector, which eliminates developer concerns and memory leaks. It has a designed for improving productivity in the development of Web applications. It has a friendly environment for all new developers. So let's do the coding.

Getting Started

First you will have to download & install the Visual Studio. Visual Studios is an open source development feel free to create any application that you want. Here's the link for the Visual Studio https://www.visualstudio.com/. Application Design We will now create the design for the application, first locate the designer file called form1.Designer.cs, this is the default name when you create a new windows form. Then write these codes inside your designer file.
  1. namespace Simple_Conversion_Application
  2. {
  3.     partial class Form1
  4.     {
  5.         /// <summary>
  6.         /// Required designer variable.
  7.         /// </summary>
  8.         private System.ComponentModel.IContainer components = null;
  9.  
  10.         /// <summary>
  11.         /// Clean up any resources being used.
  12.         /// </summary>
  13.         /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
  14.         protected override void Dispose(bool disposing)
  15.         {
  16.             if (disposing && (components != null))
  17.             {
  18.                 components.Dispose();
  19.             }
  20.             base.Dispose(disposing);
  21.         }
  22.  
  23.         #region Windows Form Designer generated code
  24.  
  25.         /// <summary>
  26.         /// Required method for Designer support - do not modify
  27.         /// the contents of this method with the code editor.
  28.         /// </summary>
  29.         private void InitializeComponent()
  30.         {
  31.             this.groupBox1 = new System.Windows.Forms.GroupBox();
  32.             this.btn_nclear = new System.Windows.Forms.Button();
  33.             this.btn_nconvert = new System.Windows.Forms.Button();
  34.             this.txt_octal = new System.Windows.Forms.TextBox();
  35.             this.txt_hexadecimal = new System.Windows.Forms.TextBox();
  36.             this.txt_binary = new System.Windows.Forms.TextBox();
  37.             this.label3 = new System.Windows.Forms.Label();
  38.             this.label4 = new System.Windows.Forms.Label();
  39.             this.label2 = new System.Windows.Forms.Label();
  40.             this.txt_number = new System.Windows.Forms.TextBox();
  41.             this.label1 = new System.Windows.Forms.Label();
  42.             this.button1 = new System.Windows.Forms.Button();
  43.             this.groupBox2 = new System.Windows.Forms.GroupBox();
  44.             this.txt_currency = new System.Windows.Forms.TextBox();
  45.             this.btn_cclear = new System.Windows.Forms.Button();
  46.             this.btn_cconvert = new System.Windows.Forms.Button();
  47.             this.label6 = new System.Windows.Forms.Label();
  48.             this.comboBox1 = new System.Windows.Forms.ComboBox();
  49.             this.txt_mon = new System.Windows.Forms.TextBox();
  50.             this.label5 = new System.Windows.Forms.Label();
  51.             this.groupBox3 = new System.Windows.Forms.GroupBox();
  52.             this.btn_tclear = new System.Windows.Forms.Button();
  53.             this.btn_tconvert = new System.Windows.Forms.Button();
  54.             this.txt_conversion = new System.Windows.Forms.TextBox();
  55.             this.label9 = new System.Windows.Forms.Label();
  56.             this.txt_totemp = new System.Windows.Forms.TextBox();
  57.             this.label8 = new System.Windows.Forms.Label();
  58.             this.comboBox2 = new System.Windows.Forms.ComboBox();
  59.             this.txt_tnumber = new System.Windows.Forms.TextBox();
  60.             this.label7 = new System.Windows.Forms.Label();
  61.             this.groupBox1.SuspendLayout();
  62.             this.groupBox2.SuspendLayout();
  63.             this.groupBox3.SuspendLayout();
  64.             this.SuspendLayout();
  65.             //
  66.             // groupBox1
  67.             //
  68.             this.groupBox1.Controls.Add(this.btn_nclear);
  69.             this.groupBox1.Controls.Add(this.btn_nconvert);
  70.             this.groupBox1.Controls.Add(this.txt_octal);
  71.             this.groupBox1.Controls.Add(this.txt_hexadecimal);
  72.             this.groupBox1.Controls.Add(this.txt_binary);
  73.             this.groupBox1.Controls.Add(this.label3);
  74.             this.groupBox1.Controls.Add(this.label4);
  75.             this.groupBox1.Controls.Add(this.label2);
  76.             this.groupBox1.Controls.Add(this.txt_number);
  77.             this.groupBox1.Controls.Add(this.label1);
  78.             this.groupBox1.Font = new System.Drawing.Font("Arial Narrow", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
  79.             this.groupBox1.Location = new System.Drawing.Point(44, 51);
  80.             this.groupBox1.Name = "groupBox1";
  81.             this.groupBox1.Size = new System.Drawing.Size(528, 573);
  82.             this.groupBox1.TabIndex = 0;
  83.             this.groupBox1.TabStop = false;
  84.             this.groupBox1.Text = "Number Conversion";
  85.             //
  86.             // btn_nclear
  87.             //
  88.             this.btn_nclear.Location = new System.Drawing.Point(273, 421);
  89.             this.btn_nclear.Name = "btn_nclear";
  90.             this.btn_nclear.Size = new System.Drawing.Size(138, 48);
  91.             this.btn_nclear.TabIndex = 10;
  92.             this.btn_nclear.Text = "CLEAR";
  93.             this.btn_nclear.UseVisualStyleBackColor = true;
  94.             this.btn_nclear.Click += new System.EventHandler(this.NClear);
  95.             //
  96.             // btn_nconvert
  97.             //
  98.             this.btn_nconvert.Location = new System.Drawing.Point(77, 421);
  99.             this.btn_nconvert.Name = "btn_nconvert";
  100.             this.btn_nconvert.Size = new System.Drawing.Size(128, 48);
  101.             this.btn_nconvert.TabIndex = 9;
  102.             this.btn_nconvert.Text = "CONVERT";
  103.             this.btn_nconvert.UseVisualStyleBackColor = true;
  104.             this.btn_nconvert.Click += new System.EventHandler(this.ConvertNumber);
  105.             //
  106.             // txt_octal
  107.             //
  108.             this.txt_octal.Enabled = false;
  109.             this.txt_octal.Location = new System.Drawing.Point(362, 267);
  110.             this.txt_octal.Multiline = true;
  111.             this.txt_octal.Name = "txt_octal";
  112.             this.txt_octal.Size = new System.Drawing.Size(137, 107);
  113.             this.txt_octal.TabIndex = 8;
  114.             //
  115.             // txt_hexadecimal
  116.             //
  117.             this.txt_hexadecimal.Enabled = false;
  118.             this.txt_hexadecimal.Location = new System.Drawing.Point(172, 267);
  119.             this.txt_hexadecimal.Multiline = true;
  120.             this.txt_hexadecimal.Name = "txt_hexadecimal";
  121.             this.txt_hexadecimal.Size = new System.Drawing.Size(167, 107);
  122.             this.txt_hexadecimal.TabIndex = 7;
  123.             this.txt_hexadecimal.Text = " ";
  124.             //
  125.             // txt_binary
  126.             //
  127.             this.txt_binary.Enabled = false;
  128.             this.txt_binary.Location = new System.Drawing.Point(22, 267);
  129.             this.txt_binary.Multiline = true;
  130.             this.txt_binary.Name = "txt_binary";
  131.             this.txt_binary.Size = new System.Drawing.Size(120, 107);
  132.             this.txt_binary.TabIndex = 6;
  133.             //
  134.             // label3
  135.             //
  136.             this.label3.AutoSize = true;
  137.             this.label3.Location = new System.Drawing.Point(400, 226);
  138.             this.label3.Name = "label3";
  139.             this.label3.Size = new System.Drawing.Size(58, 29);
  140.             this.label3.TabIndex = 5;
  141.             this.label3.Text = "Octal";
  142.             //
  143.             // label4
  144.             //
  145.             this.label4.AutoSize = true;
  146.             this.label4.Location = new System.Drawing.Point(192, 226);
  147.             this.label4.Name = "label4";
  148.             this.label4.Size = new System.Drawing.Size(126, 29);
  149.             this.label4.TabIndex = 4;
  150.             this.label4.Text = "Hexadecimal";
  151.             //
  152.             // label2
  153.             //
  154.             this.label2.AutoSize = true;
  155.             this.label2.Location = new System.Drawing.Point(46, 226);
  156.             this.label2.Name = "label2";
  157.             this.label2.Size = new System.Drawing.Size(68, 29);
  158.             this.label2.TabIndex = 2;
  159.             this.label2.Text = "Binary";
  160.             //
  161.             // txt_number
  162.             //
  163.             this.txt_number.Location = new System.Drawing.Point(226, 116);
  164.             this.txt_number.Name = "txt_number";
  165.             this.txt_number.Size = new System.Drawing.Size(206, 35);
  166.             this.txt_number.TabIndex = 1;
  167.             //
  168.             // label1
  169.             //
  170.             this.label1.AutoSize = true;
  171.             this.label1.Location = new System.Drawing.Point(46, 119);
  172.             this.label1.Name = "label1";
  173.             this.label1.Size = new System.Drawing.Size(148, 29);
  174.             this.label1.TabIndex = 0;
  175.             this.label1.Text = "Enter a number";
  176.             //
  177.             // button1
  178.             //
  179.             this.button1.Font = new System.Drawing.Font("Arial Narrow", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
  180.             this.button1.Location = new System.Drawing.Point(458, 648);
  181.             this.button1.Name = "button1";
  182.             this.button1.Size = new System.Drawing.Size(295, 51);
  183.             this.button1.TabIndex = 1;
  184.             this.button1.Text = "Exit Application";
  185.             this.button1.UseVisualStyleBackColor = true;
  186.             this.button1.Click += new System.EventHandler(this.ExitApp);
  187.             //
  188.             // groupBox2
  189.             //
  190.             this.groupBox2.Controls.Add(this.txt_currency);
  191.             this.groupBox2.Controls.Add(this.btn_cclear);
  192.             this.groupBox2.Controls.Add(this.btn_cconvert);
  193.             this.groupBox2.Controls.Add(this.label6);
  194.             this.groupBox2.Controls.Add(this.comboBox1);
  195.             this.groupBox2.Controls.Add(this.txt_mon);
  196.             this.groupBox2.Controls.Add(this.label5);
  197.             this.groupBox2.Font = new System.Drawing.Font("Arial Narrow", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
  198.             this.groupBox2.Location = new System.Drawing.Point(637, 51);
  199.             this.groupBox2.Name = "groupBox2";
  200.             this.groupBox2.Size = new System.Drawing.Size(531, 268);
  201.             this.groupBox2.TabIndex = 2;
  202.             this.groupBox2.TabStop = false;
  203.             this.groupBox2.Text = "Currency Conversion";
  204.             //
  205.             // txt_currency
  206.             //
  207.             this.txt_currency.Location = new System.Drawing.Point(106, 154);
  208.             this.txt_currency.Name = "txt_currency";
  209.             this.txt_currency.ReadOnly = true;
  210.             this.txt_currency.Size = new System.Drawing.Size(327, 35);
  211.             this.txt_currency.TabIndex = 6;
  212.             //
  213.             // btn_cclear
  214.             //
  215.             this.btn_cclear.Location = new System.Drawing.Point(296, 206);
  216.             this.btn_cclear.Name = "btn_cclear";
  217.             this.btn_cclear.Size = new System.Drawing.Size(143, 49);
  218.             this.btn_cclear.TabIndex = 5;
  219.             this.btn_cclear.Text = "CLEAR";
  220.             this.btn_cclear.UseVisualStyleBackColor = true;
  221.             this.btn_cclear.Click += new System.EventHandler(this.CClear);
  222.             //
  223.             // btn_cconvert
  224.             //
  225.             this.btn_cconvert.Location = new System.Drawing.Point(89, 206);
  226.             this.btn_cconvert.Name = "btn_cconvert";
  227.             this.btn_cconvert.Size = new System.Drawing.Size(138, 49);
  228.             this.btn_cconvert.TabIndex = 4;
  229.             this.btn_cconvert.Text = "CONVERT";
  230.             this.btn_cconvert.UseVisualStyleBackColor = true;
  231.             this.btn_cconvert.Click += new System.EventHandler(this.ConvertCurrency);
  232.             //
  233.             // label6
  234.             //
  235.             this.label6.AutoSize = true;
  236.             this.label6.Location = new System.Drawing.Point(114, 105);
  237.             this.label6.Name = "label6";
  238.             this.label6.Size = new System.Drawing.Size(93, 29);
  239.             this.label6.TabIndex = 3;
  240.             this.label6.Text = "Currency";
  241.             //
  242.             // comboBox1
  243.             //
  244.             this.comboBox1.FormattingEnabled = true;
  245.             this.comboBox1.Items.AddRange(new object[] {
  246.             "Dollar",
  247.             "Rupee",
  248.             "Euro",
  249.             "Yen",
  250.             "Won"});
  251.             this.comboBox1.Location = new System.Drawing.Point(230, 100);
  252.             this.comboBox1.Name = "comboBox1";
  253.             this.comboBox1.Size = new System.Drawing.Size(203, 37);
  254.             this.comboBox1.TabIndex = 2;
  255.             //
  256.             // txt_mon
  257.             //
  258.             this.txt_mon.Location = new System.Drawing.Point(230, 48);
  259.             this.txt_mon.Name = "txt_mon";
  260.             this.txt_mon.Size = new System.Drawing.Size(209, 35);
  261.             this.txt_mon.TabIndex = 1;
  262.             //
  263.             // label5
  264.             //
  265.             this.label5.AutoSize = true;
  266.             this.label5.Location = new System.Drawing.Point(59, 51);
  267.             this.label5.Name = "label5";
  268.             this.label5.Size = new System.Drawing.Size(148, 29);
  269.             this.label5.TabIndex = 0;
  270.             this.label5.Text = "Enter a number";
  271.             //
  272.             // groupBox3
  273.             //
  274.             this.groupBox3.Controls.Add(this.btn_tclear);
  275.             this.groupBox3.Controls.Add(this.btn_tconvert);
  276.             this.groupBox3.Controls.Add(this.txt_conversion);
  277.             this.groupBox3.Controls.Add(this.label9);
  278.             this.groupBox3.Controls.Add(this.txt_totemp);
  279.             this.groupBox3.Controls.Add(this.label8);
  280.             this.groupBox3.Controls.Add(this.comboBox2);
  281.             this.groupBox3.Controls.Add(this.txt_tnumber);
  282.             this.groupBox3.Controls.Add(this.label7);
  283.             this.groupBox3.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
  284.             this.groupBox3.Location = new System.Drawing.Point(637, 341);
  285.             this.groupBox3.Name = "groupBox3";
  286.             this.groupBox3.Size = new System.Drawing.Size(531, 283);
  287.             this.groupBox3.TabIndex = 3;
  288.             this.groupBox3.TabStop = false;
  289.             this.groupBox3.Text = "Tempature Conversion";
  290.             //
  291.             // btn_tclear
  292.             //
  293.             this.btn_tclear.Location = new System.Drawing.Point(270, 220);
  294.             this.btn_tclear.Name = "btn_tclear";
  295.             this.btn_tclear.Size = new System.Drawing.Size(142, 40);
  296.             this.btn_tclear.TabIndex = 8;
  297.             this.btn_tclear.Text = "CLEAR";
  298.             this.btn_tclear.UseVisualStyleBackColor = true;
  299.             this.btn_tclear.Click += new System.EventHandler(this.TClear);
  300.             //
  301.             // btn_tconvert
  302.             //
  303.             this.btn_tconvert.Location = new System.Drawing.Point(89, 220);
  304.             this.btn_tconvert.Name = "btn_tconvert";
  305.             this.btn_tconvert.Size = new System.Drawing.Size(145, 40);
  306.             this.btn_tconvert.TabIndex = 7;
  307.             this.btn_tconvert.Text = "CONVERT";
  308.             this.btn_tconvert.UseVisualStyleBackColor = true;
  309.             this.btn_tconvert.Click += new System.EventHandler(this.ConverTemperature);
  310.             //
  311.             // txt_conversion
  312.             //
  313.             this.txt_conversion.Location = new System.Drawing.Point(270, 160);
  314.             this.txt_conversion.Name = "txt_conversion";
  315.             this.txt_conversion.ReadOnly = true;
  316.             this.txt_conversion.Size = new System.Drawing.Size(169, 35);
  317.             this.txt_conversion.TabIndex = 6;
  318.             //
  319.             // label9
  320.             //
  321.             this.label9.AutoSize = true;
  322.             this.label9.Location = new System.Drawing.Point(39, 163);
  323.             this.label9.Name = "label9";
  324.             this.label9.Size = new System.Drawing.Size(43, 29);
  325.             this.label9.TabIndex = 5;
  326.             this.label9.Text = "To";
  327.             //
  328.             // txt_totemp
  329.             //
  330.             this.txt_totemp.Location = new System.Drawing.Point(89, 160);
  331.             this.txt_totemp.Name = "txt_totemp";
  332.             this.txt_totemp.ReadOnly = true;
  333.             this.txt_totemp.Size = new System.Drawing.Size(127, 35);
  334.             this.txt_totemp.TabIndex = 4;
  335.             //
  336.             // label8
  337.             //
  338.             this.label8.AutoSize = true;
  339.             this.label8.Location = new System.Drawing.Point(72, 109);
  340.             this.label8.Name = "label8";
  341.             this.label8.Size = new System.Drawing.Size(135, 29);
  342.             this.label8.TabIndex = 3;
  343.             this.label8.Text = "Conversion";
  344.             //
  345.             // comboBox2
  346.             //
  347.             this.comboBox2.FormattingEnabled = true;
  348.             this.comboBox2.Items.AddRange(new object[] {
  349.             "Fahrenheit",
  350.             "Celsius"});
  351.             this.comboBox2.Location = new System.Drawing.Point(223, 106);
  352.             this.comboBox2.Name = "comboBox2";
  353.             this.comboBox2.Size = new System.Drawing.Size(216, 37);
  354.             this.comboBox2.TabIndex = 2;
  355.             this.comboBox2.SelectedIndexChanged += new System.EventHandler(this.ChangeSelection);
  356.             //
  357.             // txt_tnumber
  358.             //
  359.             this.txt_tnumber.Location = new System.Drawing.Point(223, 52);
  360.             this.txt_tnumber.Name = "txt_tnumber";
  361.             this.txt_tnumber.Size = new System.Drawing.Size(216, 35);
  362.             this.txt_tnumber.TabIndex = 1;
  363.             //
  364.             // label7
  365.             //
  366.             this.label7.AutoSize = true;
  367.             this.label7.Location = new System.Drawing.Point(39, 55);
  368.             this.label7.Name = "label7";
  369.             this.label7.Size = new System.Drawing.Size(177, 29);
  370.             this.label7.TabIndex = 0;
  371.             this.label7.Text = "Enter a number";
  372.             //
  373.             // Form1
  374.             //
  375.             this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F);
  376.             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
  377.             this.ClientSize = new System.Drawing.Size(1214, 739);
  378.             this.Controls.Add(this.groupBox3);
  379.             this.Controls.Add(this.groupBox2);
  380.             this.Controls.Add(this.button1);
  381.             this.Controls.Add(this.groupBox1);
  382.             this.Name = "Form1";
  383.             this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
  384.             this.Text = "Simple Conversion Application";
  385.             this.groupBox1.ResumeLayout(false);
  386.             this.groupBox1.PerformLayout();
  387.             this.groupBox2.ResumeLayout(false);
  388.             this.groupBox2.PerformLayout();
  389.             this.groupBox3.ResumeLayout(false);
  390.             this.groupBox3.PerformLayout();
  391.             this.ResumeLayout(false);
  392.  
  393.         }
  394.  
  395.         #endregion
  396.  
  397.         private System.Windows.Forms.GroupBox groupBox1;
  398.         private System.Windows.Forms.Button button1;
  399.         private System.Windows.Forms.TextBox txt_octal;
  400.         private System.Windows.Forms.TextBox txt_hexadecimal;
  401.         private System.Windows.Forms.TextBox txt_binary;
  402.         private System.Windows.Forms.Label label3;
  403.         private System.Windows.Forms.Label label4;
  404.         private System.Windows.Forms.Label label2;
  405.         private System.Windows.Forms.TextBox txt_number;
  406.         private System.Windows.Forms.Label label1;
  407.         private System.Windows.Forms.GroupBox groupBox2;
  408.         private System.Windows.Forms.GroupBox groupBox3;
  409.         private System.Windows.Forms.Button btn_nclear;
  410.         private System.Windows.Forms.Button btn_nconvert;
  411.         private System.Windows.Forms.ComboBox comboBox1;
  412.         private System.Windows.Forms.TextBox txt_mon;
  413.         private System.Windows.Forms.Label label5;
  414.         private System.Windows.Forms.Button btn_cclear;
  415.         private System.Windows.Forms.Button btn_cconvert;
  416.         private System.Windows.Forms.Label label6;
  417.         private System.Windows.Forms.TextBox txt_currency;
  418.         private System.Windows.Forms.Button btn_tclear;
  419.         private System.Windows.Forms.Button btn_tconvert;
  420.         private System.Windows.Forms.TextBox txt_conversion;
  421.         private System.Windows.Forms.Label label9;
  422.         private System.Windows.Forms.TextBox txt_totemp;
  423.         private System.Windows.Forms.Label label8;
  424.         private System.Windows.Forms.ComboBox comboBox2;
  425.         private System.Windows.Forms.TextBox txt_tnumber;
  426.         private System.Windows.Forms.Label label7;
  427.     }
  428. }
or also you create the layout by dragging the designating tools to the forms.

Creating the Script

This code contains the function of the application. This code contains the three main functionnalities of the application. The three are the Number Conversion, Currency Converter, and Temperature conversion. To do that locate the csharp script, In my case the default script will be called Form1.cs. Then write these block of codes inside the Class of the form called Form1.
  1.  private void NClear(object sender, EventArgs e) {
  2.             txt_binary.Text = "";
  3.             txt_hexadecimal.Text = "";
  4.             txt_octal.Text = "";
  5.             txt_number.Text = "";
  6.         }
  7.  
  8.         private void ExitApp(object sender, EventArgs e) {
  9.             Application.Exit();
  10.         }
  11.  
  12.         private void ConvertNumber(object sender, EventArgs e) {
  13.  
  14.             if (txt_number.Text != "")
  15.             {
  16.                 int num = int.Parse(txt_number.Text);
  17.  
  18.                 txt_binary.Text = Convert.ToString(num, 2);
  19.                 txt_hexadecimal.Text = Convert.ToString(num, 16);
  20.                 txt_octal.Text = Convert.ToString(num, 8);
  21.             }
  22.         }
  23.  
  24.         private void CClear(object sender, EventArgs e) {
  25.             txt_mon.Text = "";
  26.             txt_currency.Text = "";
  27.             comboBox1.Text = "";
  28.         }
  29.  
  30.         private void ConvertCurrency(object sender, EventArgs e)
  31.         {
  32.             if (txt_mon.Text != "" && comboBox1.Text != "")
  33.             {
  34.                 Double num = Double.Parse(txt_mon.Text);
  35.  
  36.                 switch (comboBox1.Text)
  37.                 {
  38.                     case "Dollar":
  39.                         txt_currency.Text = Convert.ToString(num * 50);
  40.                         break;
  41.  
  42.                     case "Rupee":
  43.                         txt_currency.Text = Convert.ToString(num * 1.25);
  44.                         break;
  45.  
  46.                     case "Euro":
  47.                         txt_currency.Text = Convert.ToString(num * 0.016);
  48.                         break;
  49.  
  50.                     case "Yen":
  51.                         txt_currency.Text = Convert.ToString(num * 2.06);
  52.                         break;
  53.  
  54.                     case "Won":
  55.                         txt_currency.Text = Convert.ToString(num * 58.56);
  56.                         break;
  57.                 }
  58.             }
  59.         }
  60.  
  61.         private void TClear(object sender, EventArgs e) {
  62.             txt_totemp.Text = "";
  63.             comboBox2.Text = "";
  64.             txt_tnumber.Text = "";
  65.             txt_conversion.Text = "";
  66.         }
  67.  
  68.         private void ChangeSelection(object sender, EventArgs e)
  69.         {
  70.             if (comboBox2.Text == "Fahrenheit") {
  71.                 txt_totemp.Text = "Celsius";
  72.             } else if (comboBox2.Text == "Celsius") {
  73.                 txt_totemp.Text = "Fahrenheit";
  74.             }
  75.         }
  76.  
  77.         private void ConverTemperature(object sender, EventArgs e) {
  78.             Double num = Double.Parse(txt_tnumber.Text);
  79.  
  80.             if (txt_tnumber.Text != "" && comboBox2.Text != "") {
  81.  
  82.                 if (comboBox2.Text == "Fahrenheit")
  83.                 {
  84.                     txt_conversion.Text = Convert.ToString(((num - 32) / 9) * 5);
  85.                 } else if (comboBox2.Text == "Celsius") {
  86.                     txt_conversion.Text = Convert.ToString(((num * 9) / 5) + 32);
  87.                 }
  88.             }
  89.         }
Try to run the application and see if it works. There you go we successfully create a Simple Conversion Application using C#. I hope that this tutorial help you understand on how to develop an application using C#. For more updates and tutorials just kindly visit this site. Enjoy Coding!!!

Add new comment