so here the program......
snapshots:
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 WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
Double fno, sno, result;
private void btn_add_Click(object sender, EventArgs e)
{
int I = Controls.Count;
for (int i = 0; i < I; i++)
{
if ((String)(Controls[i].Tag) == "A" && Controls[i].Text == "")
{
MessageBox.Show("you have not entered values in " + Controls[i].Name, "error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
Controls[i].Focus();
return;
}
}
fno = Double.Parse(txt_fno.Text);
sno = Double.Parse(txt_sno.Text);
result = fno + sno;
txt_result.Text = result.ToString();
lbl_result.Text = "Sum";
lbl_result.Visible = true;
txt_result.Visible = true;
}
private void btn_sub_Click(object sender, EventArgs e)
{
int I = Controls.Count;
for (int i = 0; i < I; i++)
{
if ((String)(Controls[i].Tag) == "S" && Controls[i].Text == "")
{
MessageBox.Show("you have not entered values in " + Controls[i].Name, "error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
Controls[i].Focus();
return;
}
}
fno = Double.Parse(txt_fno.Text);
sno = Double.Parse(txt_sno.Text);
result = fno - sno;
txt_result.Text = result.ToString();
lbl_result.Text = "Subtract";
lbl_result.Visible = true;
}
private void btn_mul_Click(object sender, EventArgs e)
{
int I = Controls.Count;
for (int i = 0; i < I; i++)
{
if ((String)(Controls[i].Tag) == "M" && Controls[i].Text == "")
{
MessageBox.Show("you have not entered values in " + Controls[i].Name, "error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
Controls[i].Focus();
return;
}
}
fno = Double.Parse(txt_fno.Text);
sno = Double.Parse(txt_sno.Text);
result = fno * sno;
txt_result.Text = result.ToString();
lbl_result.Text = "Multiplication";
lbl_result.Visible = true;
}
private void btn_div_Click(object sender, EventArgs e)
{
int I = Controls.Count;
for (int i = 0; i < I; i++)
{
if ((String)(Controls[i].Tag) == "D" && Controls[i].Text == "")
{
MessageBox.Show("you have not entered values in " + Controls[i].Name, "error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
Controls[i].Focus();
return;
}
}
fno = Double.Parse(txt_fno.Text);
sno = Double.Parse(txt_sno.Text);
if (sno == 0)
{
MessageBox.Show("not allowed");
txt_sno.Focus();
txt_sno.SelectionStart = 0;
txt_sno.SelectionLength = txt_sno.Text.Length;
}
result = fno / sno;
txt_result.Text = result.ToString();
lbl_result.Text = "Division";
lbl_result.Visible = true;
}
private void txt_fno_TextChanged(object sender, EventArgs e)
{
try
{
fno = Double.Parse(txt_fno.Text);
}
catch
{
SendKeys.Send("{BACKSPACE}");
}
}
private void txt_sno_TextChanged(object sender, EventArgs e)
{
try
{
sno = Double.Parse(txt_sno.Text);
}
catch
{
SendKeys.Send("{BACKSPACE}");
}
}
private void txt_fno_Validating(object sender, CancelEventArgs e)
{
if (txt_fno.Text == "")
e.Cancel = true;
}
private void txt_sno_Validating(object sender, CancelEventArgs e)
{
if (txt_sno.Text == "")
e.Cancel = true;
}
private void btn_reset_Click(object sender, EventArgs e)
{
txt_fno.Text = "";
txt_sno.Text = "";
txt_result.Text = "";
txt_fno.Focus();
}
private void btn_quit_Click(object sender, EventArgs e)
{
Application.Exit();
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
Double fno, sno, result;
private void btn_add_Click(object sender, EventArgs e)
{
int I = Controls.Count;
for (int i = 0; i < I; i++)
{
if ((String)(Controls[i].Tag) == "A" && Controls[i].Text == "")
{
MessageBox.Show("you have not entered values in " + Controls[i].Name, "error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
Controls[i].Focus();
return;
}
}
fno = Double.Parse(txt_fno.Text);
sno = Double.Parse(txt_sno.Text);
result = fno + sno;
txt_result.Text = result.ToString();
lbl_result.Text = "Sum";
lbl_result.Visible = true;
txt_result.Visible = true;
}
private void btn_sub_Click(object sender, EventArgs e)
{
int I = Controls.Count;
for (int i = 0; i < I; i++)
{
if ((String)(Controls[i].Tag) == "S" && Controls[i].Text == "")
{
MessageBox.Show("you have not entered values in " + Controls[i].Name, "error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
Controls[i].Focus();
return;
}
}
fno = Double.Parse(txt_fno.Text);
sno = Double.Parse(txt_sno.Text);
result = fno - sno;
txt_result.Text = result.ToString();
lbl_result.Text = "Subtract";
lbl_result.Visible = true;
}
private void btn_mul_Click(object sender, EventArgs e)
{
int I = Controls.Count;
for (int i = 0; i < I; i++)
{
if ((String)(Controls[i].Tag) == "M" && Controls[i].Text == "")
{
MessageBox.Show("you have not entered values in " + Controls[i].Name, "error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
Controls[i].Focus();
return;
}
}
fno = Double.Parse(txt_fno.Text);
sno = Double.Parse(txt_sno.Text);
result = fno * sno;
txt_result.Text = result.ToString();
lbl_result.Text = "Multiplication";
lbl_result.Visible = true;
}
private void btn_div_Click(object sender, EventArgs e)
{
int I = Controls.Count;
for (int i = 0; i < I; i++)
{
if ((String)(Controls[i].Tag) == "D" && Controls[i].Text == "")
{
MessageBox.Show("you have not entered values in " + Controls[i].Name, "error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
Controls[i].Focus();
return;
}
}
fno = Double.Parse(txt_fno.Text);
sno = Double.Parse(txt_sno.Text);
if (sno == 0)
{
MessageBox.Show("not allowed");
txt_sno.Focus();
txt_sno.SelectionStart = 0;
txt_sno.SelectionLength = txt_sno.Text.Length;
}
result = fno / sno;
txt_result.Text = result.ToString();
lbl_result.Text = "Division";
lbl_result.Visible = true;
}
private void txt_fno_TextChanged(object sender, EventArgs e)
{
try
{
fno = Double.Parse(txt_fno.Text);
}
catch
{
SendKeys.Send("{BACKSPACE}");
}
}
private void txt_sno_TextChanged(object sender, EventArgs e)
{
try
{
sno = Double.Parse(txt_sno.Text);
}
catch
{
SendKeys.Send("{BACKSPACE}");
}
}
private void txt_fno_Validating(object sender, CancelEventArgs e)
{
if (txt_fno.Text == "")
e.Cancel = true;
}
private void txt_sno_Validating(object sender, CancelEventArgs e)
{
if (txt_sno.Text == "")
e.Cancel = true;
}
private void btn_reset_Click(object sender, EventArgs e)
{
txt_fno.Text = "";
txt_sno.Text = "";
txt_result.Text = "";
txt_fno.Focus();
}
private void btn_quit_Click(object sender, EventArgs e)
{
Application.Exit();
}
}
}
No comments:
Post a Comment