i need calculater code for c# visual studio 2010 i tried many but not working plz help....also tell some useful websites for c# tutorials n projects.
i need calculater code for c# visual studio 2010 i tried many but not working plz help....also tell some useful websites for c# tutorials n projects.
Drag the following controls to the form:
1 textboxe, 10 buttons:
Change the textbox text property to 0
Let's also add 4 labels to the Form:
Start adding the labels from the left to the right on the form, then change their text property to 0:
You also should change the visible property of the labels to False. (The 4 labels will hide when you play the calculator)
Now let's add the code to the 10 buttons.
Scroll down to Click event and double click on the blank cell:
Then add the following highlighted code:
private void button10_Click(object sender, EventArgs e)
{
//check if the application need to clear the screen first
if (textBox1.Text == label2.Text)
// Hit Clear button: in this case it is button 17 (note that you might see an error because you havent added clear button,
//just ignore the error for a little bit
button17.PerformClick();
//Textbox 1 will display the text of the pressed button:
Button clickedButton = (Button)sender;
textBox1.Text = textBox1.Text + clickedButton.Text ;
}
Lets add the rest of the 5 math symbols: + - * / = to the form:
Change their text property to the math symbol like the picture below:
Programming the addition button: double click on + button and add the following highlighted code:
private void button13_Click(object sender, EventArgs e)
{
try
{
label2.Text = textBox1.Text;
double operand = Convert.ToDouble(label2.Text);
label4.Text = "+";
textBox1.Clear();
}
catch (Exception ex)
{
}
}
Programming the subtraction button: double click on - button and add the following highlighted code:
private void button14_Click(object sender, EventArgs e)
{
try
{
label2.Text = textBox1.Text;
double operand = Convert.ToDouble(label2.Text);
label4.Text = "-";
textBox1.Clear();
}
catch (Exception ex)
{
}
}
Programming the multiplication button, double click on the * button and add the following highlighted code:
private void button15_Click(object sender, EventArgs e)
{
try
{
label2.Text = textBox1.Text;
double operand = Convert.ToDouble(label2.Text);
label4.Text = "*";
textBox1.Clear();
}
catch (Exception ex)
{
}
}
Programming the division button, double click on the / button and add the following highlighted code:
private void button16_Click(object sender, EventArgs e)
{
try
{
label2.Text = textBox1.Text;
double operand = Convert.ToDouble(label2.Text);
label4.Text = "/";
textBox1.Clear();
}
catch (Exception ex)
{
}
}
Lets now program the equal button: double click on = button and add the following highlighted code:
private void button12_Click(object sender, EventArgs e)
{
try
{
double a = Convert.ToDouble(label1.Text);
double b = Convert.ToDouble(label2.Text);
double c = Convert.ToDouble(textBox1.Text);
{
if (label4.Text == "+")
{
a = b + c;
string d = Convert.ToString(a);
textBox1.Text = d;
label2.Text = textBox1.Text;
}
else if (label4.Text == "-")
{
a = b - c;
string f = Convert.ToString(a);
textBox1.Text = f;
label2.Text = textBox1.Text;
}
else if (label4.Text == "*")
{
a = b * c;
string f = Convert.ToString(a);
textBox1.Text = f;
label2.Text = textBox1.Text;
}
else if (label4.Text == "/")
{
a = b / c;
string f = Convert.ToString(a);
textBox1.Text = f;
label2.Text = textBox1.Text;
}
}
}
catch (Exception ex)
{
}
}
nice sharing!
Lets add the last buttons to the form:
positive/negative button: +/-
Exit Button:
Clear Button
Decimal Button:
Programming the Decimal button:
private void button11_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + ;
}
Programming the Positive/Negative button:
private void button19_Click(object sender, EventArgs e)
{
double a = Convert.ToDouble(textBox1.Text);
a = (-1) * a;
textBox1.Text = a.ToString();
}
Programming the Clear button:
private void button17_Click(object sender, EventArgs e)
{
textBox1.Clear();
label1.Text = "0";
label2.Text = "0";
label3.Text = "0";
label4.Text = "0";
}
Programming the Exit Button:
private void button18_Click(object sender, EventArgs e)
{
Application.Exit();
}
Run your application and test the Calculator
Source: C# Calculator
thankzzzz alot v nice
c# learning n tutorials ki koi site bta den plzzzz how v can make a login form in c#
Bookmarks