0% found this document useful (0 votes)
54 views

Proiect Minicalculator

The document describes the creation and functionality of a simple calculator application created in C# using Visual Studio. It provides instructions for setting up the user interface of the calculator, including adding buttons for numbers, operators, and functions. It then implements the code behind for handling button clicks and performing the basic mathematical operations. The application takes input from the buttons, performs the calculations, and displays the results in a text box.

Uploaded by

Anonymous gq6x0g
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views

Proiect Minicalculator

The document describes the creation and functionality of a simple calculator application created in C# using Visual Studio. It provides instructions for setting up the user interface of the calculator, including adding buttons for numbers, operators, and functions. It then implements the code behind for handling button clicks and performing the basic mathematical operations. The application takes input from the buttons, performs the calculations, and displays the results in a text box.

Uploaded by

Anonymous gq6x0g
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 6

Proiect C#

Minicalculator

Partea I

1. Deschideti Visual C# Express Edition 2010


2. Creati un proiect de tipul Windows Forms Application cu numele Minicalculator si salvati-
l in folderul D:/12C
3. Pentru forma principala setati (in fereastra Properties) urmatoarele proprietati:
(Name): Form1
BackColor: Control (din tabul System)
Font: Microsoft Sans Serif 8.25 Bold
ForeColor: ControlText (din tabul System)
FormBorderStyle: FixedDialog
MaximizeBox: False
MinimizeBox: False
Size: 316, 315
Text: Minicalculator

4. Adaugati pe forma un control Button si setati urmatoarele proprietati:


(Name): exitButton
Location: 21, 3
Size: 65, 27
Text: Exit
5. Adaugati pe forma un control Button si setati urmatoarele proprietati:
(Name): clearButton
Location: 225, 3
Size: 65, 27
Text: Clear

6. Adaugati pe forma din Toolbox un control TextBox si setati urmatoarele proprietati:


(Name): textBox
Location: 53, 36
ReadOnly: True
RghtToLeft: No
Size: 200, 24
TextAlign: Right

7. Adaugati pe forma un control Panel si setati urmatoarele proprietati:


(Name): Panel
BorderStyle: Fixed3D
Location: 53, 81
Size: 200, 185

8. Adaugati pe forma, in interiorul controlului Panel, 18 controale Button si setati, in ordine,


urmatoarele proprietati:
(Name): semnButton Text: -/+
Location: 20, 8
Size: 52, 24 (Name): radicalButton
1
Location: 78, 8 Text: 6
Size: 52, 24
Text: sqrt (Name): scadereButton
Location: 135, 73
(Name): impartireButton Size: 32, 28
Location: 135, 8 Text: -
Size: 32, 28
Text: / (Name): unuButton
Location: 20, 103
(Name): sapteButton Size: 32, 28
Location: 20, 44 Text: 1
Size: 32, 28
Text: 7 (Name): doiButton
Location: 59, 103
(Name): optButton Size: 32, 28
Location: 59, 44 Text: 2
Size: 32, 28
Text: 8 (Name): treiButton
Location: 97, 103
(Name): nouaButton Size: 32, 28
Location: 97, 44 Text: 3
Size: 32, 28
Text: 9 (Name): adunareButton
Location: 135, 103
(Name): produsButton Size: 32, 57
Location: 135, 44 Text: +
Size: 32, 28
Text: x (Name): zeroButton
Location: 21, 134
(Name): patruButton Size: 32, 28
Location: 20, 73 Text: 0
Size: 32, 28
Text: 4 (Name): virgulaButton
Location: 59, 134
(Name): cinciButton Size: 32, 28
Location: 58, 73 Text: .
Size: 32, 28
Text: 5 (Name): egalButton
Location: 97, 134
(Name): saseButton Size: 32, 28
Location: 97, 73 Text: =
Size: 32, 28

Forma dvs. ar trebui sa arate astfel:

2
Alegeti BuildBuild Solution (sau F6) ca sa compilati proiectul

Alegeti DebugStart Debugging (sau F5) ca sa lansati in executie aplicatia

Salvati proiectul si inchideti aplicatia.

3
Proiect C#

Minicalculator

Partea a II-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 Minicalculator
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
double nr1, nr2;
int operat=0;
string s="";

private void exitButton_Click(object sender, EventArgs e)


{
this.Close(); ;
}

private void clearButton_Click(object sender, EventArgs e)


{
textBox.Clear();
s = "";
}

private void semnButton_Click(object sender, EventArgs e)


{
s+="-";
textBox.Text=s;
}

private void zeroButton_Click(object sender, EventArgs e)


{
s+="0";
textBox.Text=s;
}

private void virgulaButton_Click(object sender, EventArgs e)


{
s+=".";
textBox.Text=s;
}

private void unuButton_Click(object sender, EventArgs e)


{
s+="1";
textBox.Text=s;
4
}

private void doiButton_Click(object sender, EventArgs e)


{
s+="2";
textBox.Text=s;
}

private void treiButton_Click(object sender, EventArgs e)


{
s+="3";
textBox.Text=s;
}

private void patruButton_Click(object sender, EventArgs e)


{
s+="4";
textBox.Text=s;
}

private void cinciButton_Click(object sender, EventArgs e)


{
s+="5";
textBox.Text=s;
}

private void saseButton_Click(object sender, EventArgs e)


{
s+="6";
textBox.Text=s;
}

private void sapteButton_Click(object sender, EventArgs e)


{
s+="7";
textBox.Text=s;
}

private void optButton_Click(object sender, EventArgs e)


{
s+="8";
textBox.Text=s;
}

private void nouaButton_Click(object sender, EventArgs e)


{
s+="9";
textBox.Text=s;
}

private void adunareButton_Click(object sender, EventArgs e)


{
operat=1;
nr1=double.Parse(s);
s="";
textBox.Text=s;
}

private void scadereButton_Click(object sender, EventArgs e)


{
operat=2;
nr1 = double.Parse(s);
s="";
textBox.Text=s;
}

5
private void produsButton_Click(object sender, EventArgs e)
{
operat = 3;
nr1 = double.Parse(s);
s = "";
textBox.Text = s;
}

private void impartireButton_Click(object sender, EventArgs e)


{
operat = 4;
nr1=double.Parse(s);
s = "";
textBox.Text = s;
}

private void radicalButton_Click(object sender, EventArgs e)


{
operat = 5;
nr1 = double.Parse(s);
if (nr1 > 0)
{
double a = Math.Sqrt(nr1);
s = "";
s += a;
textBox.Text = s;
}
else
textBox.Text = "Err-sqrt from negative number";

private void egalButton_Click(object sender, EventArgs e)


{
nr2 = double.Parse(s);
s="";
switch(operat)
{
case 1: s=(nr1+nr2).ToString();
break;
case 2: s=(nr1-nr2).ToString();
break;
case 3: s=(nr1*nr2).ToString();
break;
case 4: if(nr2==0)
s="Err-divide by zero";
else
s=(nr1/nr2).ToString();
break;
}
textBox.Text=s;

}
}
}

You might also like