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

Program Calculator Visual CSharp

The document contains code for a C# Windows Forms application that implements a basic calculator interface. It defines event handler methods for buttons that display numbers, arithmetic operators, and functions. The buttons populate a view text box and perform calculations when the equals button is clicked by parsing the view as a double and applying the correct arithmetic or function based on the stored operation name. The code provides the basic functionality for a simple calculator application through the Windows Forms user interface.

Uploaded by

Dwiky firmansyah
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)
39 views

Program Calculator Visual CSharp

The document contains code for a C# Windows Forms application that implements a basic calculator interface. It defines event handler methods for buttons that display numbers, arithmetic operators, and functions. The buttons populate a view text box and perform calculations when the equals button is clicked by parsing the view as a double and applying the correct arithmetic or function based on the stored operation name. The code provides the basic functionality for a simple calculator application through the Windows Forms user interface.

Uploaded by

Dwiky firmansyah
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

using System;

using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace latihan_aritmatika_Csharp
{
public partial class Form1 : Form
{
Double value;
String nama;
Boolean bol;
public Form1()
{

InitializeComponent();
}

private void view_TextChanged(object sender, EventArgs e)


{

private void val1_Click(object sender, EventArgs e)


{
if (view.Text == "0" )
{
view.Clear();
}

Button b = (Button)sender;
view.Text += b.Text;
}

private void val2_Click(object sender, EventArgs e)


{
if (view.Text == "0")
{
view.Clear();
}

Button b = (Button)sender;
view.Text += b.Text;
}

private void val3_Click(object sender, EventArgs e)


{
if (view.Text == "0")
{
view.Clear();
}

Button b = (Button)sender;
view.Text += b.Text;
}

private void val4_Click(object sender, EventArgs e)


{
if (view.Text == "0")
{
view.Clear();
}

Button b = (Button)sender;
view.Text += b.Text;
}

private void val5_Click(object sender, EventArgs e)


{
if (view.Text == "0")
{
view.Clear();
}

Button b = (Button)sender;
view.Text += b.Text;
}

private void val6_Click(object sender, EventArgs e)


{
if (view.Text == "0")
{
view.Clear();
}

Button b = (Button)sender;
view.Text += b.Text;
}

private void val7_Click(object sender, EventArgs e)


{
if (view.Text == "0")
{
view.Clear();
}

Button b = (Button)sender;
view.Text += b.Text;
}

private void val8_Click(object sender, EventArgs e)


{
if (view.Text == "0")
{
view.Clear();
}

Button b = (Button)sender;
view.Text += b.Text;
}
private void val9_Click(object sender, EventArgs e)
{
if (view.Text == "0")
{
view.Clear();
}

Button b = (Button)sender;
view.Text += b.Text;
}

private void val0_Click(object sender, EventArgs e)


{
if (view.Text == "0")
{
view.Clear();
}

Button b = (Button)sender;
view.Text += b.Text;
}

private void clear_Click(object sender, EventArgs e)


{
view.Text = "0";
}

private void Form1_Load(object sender, EventArgs e)


{

private void tambah_Click(object sender, EventArgs e)


{
Button b = (Button)sender;
nama = b.Text;
value = Double.Parse(view.Text);
view.Clear();

bol = true;

private void kurang_Click(object sender, EventArgs e)


{
Button b = (Button)sender;
nama = b.Text;
value = Double.Parse(view.Text);
view.Clear();

bol = true;
}

private void kali_Click(object sender, EventArgs e)


{
Button b = (Button)sender;
nama = b.Text;
value = Double.Parse(view.Text);
view.Clear();

bol = true;
}

private void bagi_Click(object sender, EventArgs e)


{
Button b = (Button)sender;
nama = b.Text;
value = Double.Parse(view.Text);
view.Clear();

bol = true;
}

private void titik_Click(object sender, EventArgs e)


{
if (view.Text == "0")
{
view.Clear();
}

Button b = (Button)sender;
view.Text += b.Text;

private void sama_dengan_Click(object sender, EventArgs e)


{
switch(nama)
{
case "+":
view.Text = (value + Double.Parse(view.Text)).ToString();
break;

case "-":
view.Text = (value - Double.Parse(view.Text)).ToString();
break;

case "X":
view.Text = (value * Double.Parse(view.Text)).ToString();
break;

case "/":
view.Text = (value / Double.Parse(view.Text)).ToString();
break;
}
}

private void persen_Click(object sender, EventArgs e)


{
view.Text = (Double.Parse(view.Text) * 0.01).ToString();
}

private void akar1_Click(object sender, EventArgs e)


{
view.Text = (Math.Sqrt(Double.Parse(view.Text))).ToString();
}
private void Reciprocal_Click(object sender, EventArgs e)
{
view.Text = (1 / Double.Parse(view.Text)).ToString();
}

private void hapus_satu_Click(object sender, EventArgs e)


{
view.Text = view.Text.Remove(view.Text.Length - 1, 1);
}

private void exitToolStripMenuItem_Click(object sender, EventArgs e)


{
Application.Exit();
}
}
}

You might also like