Template HMI Sederhana C# VS2012

HMI_simple
FILE DOWNLOAD

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;
using System.Runtime.InteropServices;
using System.Configuration;

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

        private void timer1_Tick(object sender, EventArgs e)
        {

            //------------------------------------------------------------------
            int panjang = pictureBox1.Size.Height;
            int lebar = pictureBox1.Size.Width;
            Graphics g = this.pictureBox1.CreateGraphics();
            Pen p1 = new Pen(Color.Black, 3);
            Pen p2 = new Pen(Color.GreenYellow, 3);
            int batas_panjang = panjang * (100-level_panjang)/100;
            for (int y = 0; y < batas_panjang; y++)
            {
                g.DrawLine(p1, new Point(0, y), new Point(lebar, y));
            }
            for (int y = batas_panjang; y < panjang; y++)
            {
                g.DrawLine(p2, new Point(0, y), new Point(lebar, y));
            }
            //------------------------------------------------------------------
            //------------------------------------------------------------------
           /* label1.Text = panjang_O.ToString() + " " + lebar_O.ToString() +
                Environment.NewLine + Y.ToString() +
                Environment.NewLine + X.ToString() +
                Environment.NewLine + jarum.ToString();*/
        }
        Bitmap default_image;
        int level_panjang;
        int Stat_button1;
        private void button1_Click(object sender, EventArgs e)
        {
            if (Stat_button1 == 0)
            {
                button1.Text = "ON";
                button1.ForeColor = Color.Black;
                button1.BackColor = Color.Yellow;
                Stat_button1 = 1;
            }
            else
            {
                button1.Text = "OFF";
                button1.ForeColor = Color.White;
                button1.BackColor = Color.DarkBlue;
                Stat_button1 = 0;
            }

        }

        private void trackBar1_Scroll(object sender, EventArgs e)
        {
            level_panjang = trackBar1.Value;
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            default_image = (Bitmap)pictureBox3.Image.Clone();
            pictureBox4.Enabled = false;

            int x_ = pictureBox3.Size.Width;
            int y_ = pictureBox3.Size.Height;
            label2.Parent = pictureBox3;
            label2.BackColor = Color.Transparent;
            label2.BringToFront();
            label2.ForeColor = Color.DarkGreen;
            label2.Location = new Point(0, (int)(y_*0.7));

            button1.Text = "OFF";
            button1.ForeColor = Color.White;
            button1.BackColor = Color.DarkBlue;
        }

        int alarm_stat;
        private void timer2_Tick(object sender, EventArgs e)
        {
            float derajat = ((float)level_panjang/100) * 360;
            label2.Text = Convert.ToString((int)derajat);
            pictureBox3.Image = RotateImage(default_image, derajat-143);

            if (level_panjang > 50)
            {
                pictureBox4.Enabled = true;
                timer3.Enabled = true;

                if (alarm_stat == 0)
                {
                    if (this.WindowState == FormWindowState.Minimized)
                        this.WindowState = FormWindowState.Normal;
                    this.Show();
                    this.Activate();
                    this.ShowInTaskbar = true;
                    this.TopMost = true;
                    this.Focus();
                    alarm_stat = 1;
                }
            }
            else
            {
                pictureBox4.Enabled = false;
                timer3.Enabled = false;
                BackColor = Color.FromName("Control");
                pictureBox3.BackColor = Color.FromName("Control");

                if (alarm_stat == 1)
                {
                    this.TopMost = false;
                    alarm_stat = 0;
                }
            }
        }

        public static Image RotateImage(Image img, float rotationAngle)
        {
            //create an empty Bitmap image
            Bitmap bmp = new Bitmap(img.Width, img.Height);

            //turn the Bitmap into a Graphics object
            Graphics gfx = Graphics.FromImage(bmp);

            //now we set the rotation point to the center of our image
            gfx.TranslateTransform((float)bmp.Width / 2, (float)bmp.Height / 2);

            //now rotate the image
            gfx.RotateTransform(rotationAngle);

            gfx.TranslateTransform(-(float)bmp.Width / 2, -(float)bmp.Height / 2);

            //set the InterpolationMode to HighQualityBicubic so to ensure a high
            //quality image once it is transformed to the specified size
            gfx.InterpolationMode = InterpolationMode.HighQualityBicubic;

            //now draw our new image onto the graphics object
            gfx.DrawImage(img, new Point(0, 0));

            //dispose of our Graphics object
            gfx.Dispose();

            //return the image
            return bmp;
        }

        int stat;
        private void timer3_Tick(object sender, EventArgs e)
        {
            if (stat == 0)
            {
                BackColor = Color.Red;
                pictureBox3.BackColor = Color.Red;
                Console.Beep();
                stat = 1;
            }
            else
            {
                BackColor = Color.FromName("Control");
                pictureBox3.BackColor = Color.FromName("Control");
                stat = 0;
            }
        }

        private void timer4_Tick(object sender, EventArgs e)
        {
            label4.Text = DateTime.Now.ToString();
        }
    }
}

6 Responses to Template HMI Sederhana C# VS2012

  1. Abdi Prasetyo says:

    Mas gimana yaa caranya ngubungin C# sm PLC??

  2. abdi prasetyo says:

    ohh iyaa mas, terus ane pernah denger pake ethernet gitu gituan, ane kurang paham mas, gmn ya mksd nya??

  3. abdi says:

    mas, saya rencana nya mau tugas akhir buat gui seperti mas, tapi konek nya ke mikro mas.. ada saran buat saya utk mempelajari contoh yg seperti diatas dari awal mas??

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s