Output:
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Question_4
{
public partial class Form1 : Form
{
int Result = 0;
int a, b;
public Form1()
{
InitializeComponent();
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
if (System.Text.RegularExpressions.Regex.IsMatch(textBox1.Text, "[^0-9]"))
{
MessageBox.Show("Please Enter Only Numerical Value");
textBox1.Text=textBox1.Text.Remove(textBox1.Text.Length - 1);
}
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
if(System.Text.RegularExpressions.Regex.IsMatch(textBox2.Text, "[^0-9]"))
{
MessageBox.Show("Please Enter Only Numerical Value");
textBox2.Text=textBox2.Text.Remove(textBox2.Text.Length - 1);
}
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
a = int.Parse(textBox1.Text);
b = int.Parse(textBox2.Text);
if (comboBox1.SelectedItem.ToString() == "ADD")
{
Result = a + b;
label3.Text = Result.ToString();
}
else if (comboBox1.SelectedItem.ToString() == "SUB")
{
Result = a - b;
label3.Text = Result.ToString();
}
else if (comboBox1.SelectedItem.ToString() == "MULT")
{
Result = a * b;
label3.Text = Result.ToString();
}
else
{
Result = a / b;
label3.Text = Result.ToString();
}
}
}
}
No comments:
Post a Comment