Skip to content

Instantly share code, notes, and snippets.

@azidanit
Created March 28, 2021 07:33
Show Gist options
  • Save azidanit/2bc56aca96e8fe1a30f026d269a660d4 to your computer and use it in GitHub Desktop.
Save azidanit/2bc56aca96e8fe1a30f026d269a660d4 to your computer and use it in GitHub Desktop.
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 kalkulatorsederhana
{
public partial class Form1 : Form
{
double nilai_1, nilai_2;
public Form1()
{
InitializeComponent();
}
private void tambah_button_Click(object sender, EventArgs e)
{
this.hasil_textbox.Text = (nilai_1 + nilai_2).ToString();
}
private void kurang_button_Click(object sender, EventArgs e)
{
this.hasil_textbox.Text = (nilai_1 - nilai_2).ToString();
}
private void kali_button_Click(object sender, EventArgs e)
{
this.hasil_textbox.Text = (nilai_1 * nilai_2).ToString();
}
private void bagi_button_Click(object sender, EventArgs e)
{
if (nilai_2 == 0)
{
this.hasil_textbox.Text = "NULL, dibagi dengan 0";
}
else {
this.hasil_textbox.Text = (nilai_1 / nilai_2).ToString();
}
}
private void hapus_button_Click(object sender, EventArgs e)
{
this.hasil_textbox.Text = "";
this.nilai1_textbox.Text = "";
this.nilai2_textbox.Text = "";
}
private void nilai1_textbox_TextChanged(object sender, EventArgs e)
{
if(this.nilai1_textbox.Text!="")
this.nilai_1 = double.Parse(this.nilai1_textbox.Text);
}
private void nilai2_textbox_TextChanged(object sender, EventArgs e)
{
if (this.nilai1_textbox.Text != "")
this.nilai_2 = double.Parse(this.nilai2_textbox.Text);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment