Tugas Pertemuan 3

 Aplikasi WinForm - Kalkulator Sederhana & Webcam Capture


Nama    : Rycahaya Sri Hutomo
NRP      : 5025201046
Kelas    : Pemrograman Berbasis Kerangka Kerja D
Tahun    : Genap 2022/2023

Kalkulator Sederhana

Kalkulator Sederhana memiliki dua input nilai integer dan menghasilkan satu output hasil dari proses kedua input. Proses yang dapat dilakukan, yaitu tambah, kurang, kali, dan bagi. Selain itu, pengguna kalkulator ini juga dapat menghapus isian dari input nilai 1, nilai 2, dan hasil sekaligus. Berikut merupakan tampilan kalkulator sederhana.


Form1.cs untuk Kalkulator Sederhana

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

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void nilai1_Click(object sender, EventArgs e)
        {

        }

        private void buttonTambah_Click(object sender, EventArgs e)
        {
            int nilai1 = int.Parse(textBox1.Text);
            int nilai2 = int.Parse(textBox2.Text);
            int hasil;
            hasil = nilai1 + nilai2;
            textBox3.Text = hasil.ToString();
        }

        private void buttonKurang_Click(object sender, EventArgs e)
        {
            int nilai1 = int.Parse(textBox1.Text);
            int nilai2 = int.Parse(textBox2.Text);
            int hasil;
            hasil = nilai1 - nilai2;
            textBox3.Text = hasil.ToString();
        }

        private void buttonKali_Click(object sender, EventArgs e)
        {
            int nilai1 = int.Parse(textBox1.Text);
            int nilai2 = int.Parse(textBox2.Text);
            int hasil;
            hasil = nilai1 * nilai2;
            textBox3.Text = hasil.ToString();
        }

        private void buttonBagi_Click(object sender, EventArgs e)
        {
            int nilai1 = int.Parse(textBox1.Text);
            int nilai2 = int.Parse(textBox2.Text);
            int hasil;
            hasil = nilai1 / nilai2;
            textBox3.Text = hasil.ToString();
        }

        private void buttonClear_Click(object sender, EventArgs e)
        {
            textBox1.Text = "";
            textBox2.Text = "";
            textBox3.Text = "";
        }
    }
}

Webcam Capture App



Form1.cs untuk Webcam Capture App

using AForge.Video;
using AForge.Video.DirectShow;

namespace WebcamCaptureApp
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private VideoCaptureDevice videoCapture;
        FilterInfoCollection filterInfo;

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void buttonStartCamera_Click(object sender, EventArgs e)
        {
            startCamera();

        }

        private void startCamera()
        {
            try
            {
                filterInfo = new FilterInfoCollection(FilterCategory.VideoInputDevice);
                videoCapture = new VideoCaptureDevice(filterInfo[6].MonikerString);
                videoCapture.NewFrame += new NewFrameEventHandler(Camera_on);
                videoCapture.Start();

            }
            catch (Exception e)
            {

            }
        }

        private void Camera_on(object sender, NewFrameEventArgs eventArgs)
        {
            pictureBox1.Image = (Bitmap)eventArgs.Frame.Clone();
        }

        private void buttonCapture_Click(object sender, EventArgs e)
        {
            pictureBox2.Image = pictureBox1.Image;
            // filename location

            string filename = @"D:\ITS\Semester 6\PBKK\" + textBox1.Text + ".jpg";

            var bitmap = new Bitmap(pictureBox2.Width, pictureBox2.Height);

            pictureBox2.DrawToBitmap(bitmap, pictureBox2.ClientRectangle);

            System.Drawing.Imaging.ImageFormat imageFormat = null;

            imageFormat = System.Drawing.Imaging.ImageFormat.Jpeg;

            // save the image

            bitmap.Save(filename);
        }
    }
}

Repository Github

Kode program Kalkulator Sederhana dapat diakses di sini.
Kode program WebcamCaptureApp dapat diakses di sini.

Comments

Popular posts from this blog

EAS PBKK

Tugas Pertemuan 8

Tugas Latihan WPF