v blackcaps

v blackcaps

  • NA
  • 27
  • 3.4k

how to validate 2 textboxes it accept only numbers?

Jan 16 2020 3:46 PM
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 calculator
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
//  a simple calculator design  two textbox and 4 radio buttons result will be in the textbox3.
            double num1 = double.Parse(textBox1.Text);
            double num2 = double.Parse(textBox2.Text);
            double result=0;
           
            if (radioButton1.Checked == true)
            {
                result = num1 + num2;
            }
            else if (radioButton2.Checked == true)
            {
                result = num1 - num2;
            }
            else if (radioButton3.Checked == true)
            {
                result = num1 * num2;
            }
            else if (radioButton4.Checked == true)
            {
                result = num1 / num2;
            }
            textBox3.Text = result.ToString();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void panel2_Paint(object sender, PaintEventArgs e)
        {

        }
    }
}
sir validation is important or not i dont know  plz guide me.
 
 
wds
Blackcaps.
 
 

Answers (2)