Bob zhu - MSFT
hope follow code can fit your requirement
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace CS3
{
public partial class Form3 : Form
{
public Form3()
{
InitializeComponent();
}
private void Form3_Load(object sender, EventArgs e)
{
this.listBox1.Items.AddRange(new string[]{"+","-","*","/"});
this.textBox1.Text = this.textBox2.Text = "0";
}
private void button1_Click(object sender, EventArgs e)
{
double a, b;
a= Convert.ToDouble(this.textBox1.Text.Trim());
b = Convert.ToDouble(this.textBox2.Text.Trim());
MessageBox.Show(a.ToString() + " " + b.ToString());
if (this.listBox1.SelectedIndex == -1)
{ MessageBox.Show("select operation"); }
else
{
if (this.listBox1.SelectedIndex==3 && b == 0)
{ MessageBox.Show("Error"); }
else
switch (this.listBox1.SelectedIndex)
{
case 0: this.textBox3.Text = Convert.ToString(a + b); break;
case 1: this.textBox3.Text = Convert.ToString(a - b); break;
case 2: this.textBox3.Text = Convert.ToString(a * b); break;
case 3: this.textBox3.Text = Convert.ToString(a / b); break;
}
}
}
}
}