.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> Windows Form Controls >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Arithmetic operation and input get from Combo box(c#.net)

Posted By:laptop charles       Posted Date: December 22, 2010    Points: 15    Category: Windows Form Controls    URL: http://www.dotnetspark.com  

It has using three combobox and one textbox, combobox1 and combobox2 get input it will generate 1 to 10 numbers and other combobox will generate operator.select the input and select Arithmetic operator and it will display the result.
 

a
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 combo_indexing
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
        } 

        private void Form1_Load(object sender, EventArgs e)
        {
           
            for (int i = 1; i <= 10; i++)
            {
                comboBox1.Items.Add(i);
                comboBox2.Items.Add(i);

            }
            comboBox3.Items.Add("Add");
            comboBox3.Items.Add("Sub");
            comboBox3.Items.Add("Mul");
            comboBox3.Items.Add("Div");    
        

        }
        int x, y, z;
        private void comboBox3_SelectedIndexChanged(object sender, EventArgs e)
        {
            x = int.Parse(comboBox1.SelectedItem.ToString());

            y = int.Parse(comboBox2.SelectedItem.ToString());

         
            if (comboBox3.SelectedItem.ToString() == "Add")
            {

                z = x + y;
                textBox1.Text = z.ToString();
                

            }
            else if (comboBox3.SelectedItem.ToString() == "Sub")
            {

                z = x - y;
                textBox1.Text = z.ToString();

            }
            else if (comboBox3.SelectedItem.ToString() == "Mul")
            {

                z = x * y;
                textBox1.Text = z.ToString();

            }
            else if (comboBox3.SelectedItem.ToString() == "Div")
            {

                z = x / y;
                textBox1.Text = z.ToString();

            }
        }




    }
}

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend