Minggu, 29 Maret 2015

drawing c#

Asalammualaikum wr.wb

haii gays jumpa lagi di blog saya mardianto,disini saya akan menjelaskan program yang saya buat.
yaituuu program drawing..

Dasar Teori
Mouse adalah salah satu input komputer yang sangat penting. Mouse
sangat dibutuhkan untuk berinteraksi dengan GUI aplikasi Windows.
Dengan mouse, user dapat mengarahkan kursor, menge-klik maupun
menge-drag sebuah object. Menekan, melepaskan tombol mouse
maupun menggerakkan kursor mouse akan menghasilkan event.
Pada praktikum ini kita mencoba memanfaatkan event-event mouse
tersebut untuk menggambar grafik. Untuk menggambar pada form,
atau object lain sebagai base menggambar, kita akan menggunakan
object Graphics. Di dalam object ini terdapat beberapa method untuk
menggambar text, garis, persegi panjang dan elips.

berikut program drawing yang saya buat

/*
 * Created by SharpDevelop.
 * User: vyu
 * Date: 25/03/2015
 * Time: 5:49
 *
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;

namespace programm
{
    /// <summary>
    /// Description of MainForm.
    /// </summary>
    public partial class MainForm : Form
    {
        public Graphics bentuk;
        public bool aktif = false;
        int x, y, z, k, kx, ky;
        public bool drago = false;
        double zk;
        int a =0;
       
        public MainForm()
        {
            //
            // The InitializeComponent() call is required for Windows Forms designer support.
            //
            InitializeComponent();
           
            //
            // TODO: Add constructor code after the InitializeComponent() call.
            //
        }
        void MainFormLoad(object sender, EventArgs e)
        {
            bentuk = panel1.CreateGraphics();
        }
        void Panel1MouseClick(object sender, MouseEventArgs e)
        {
            x = e.X;
            y = e.Y;
            z = e.X - kx;
            k = ky - e.Y;
            if (aktif == true && a ==1)
            {
               
                bentuk.DrawLine(new Pen(Color.Red), kx, ky, e.X, e.Y);
            }
            else if (aktif == true && a ==2)
            {
                bentuk.DrawLine(new Pen(Color.Lime), kx, ky, e.X, e.Y);
            }
            else if (aktif == true && a ==3)
            {
                bentuk.DrawLine(new Pen(Color.Black), kx, ky, e.X, e.Y);
            }
            else if (aktif == true && a ==4)
            {
                bentuk.DrawLine(new Pen(Color.Blue), kx, ky, e.X, e.Y);
            }
            else
            {
                MessageBox.Show("Maaf anda belum memilih warna","Peringatan",MessageBoxButtons.OK,MessageBoxIcon.Warning);
            }
        }
        void Panel1MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                aktif = true;
              
            }
            kx = e.X;
            ky = e.Y;
            drago = true;
        }
        void Panel1MouseMove(object sender, MouseEventArgs e)
        {
            textBox1.Text = z.ToString();
            textBox2.Text = k.ToString();
            zk = Math.Sqrt((z*z)+(k*k));
            textBox3.Text = zk.ToString();
        }
        public void Button1Click(object sender, EventArgs e)
        {
            a = 1;
        }
        void Button4Click(object sender, EventArgs e)
        {
            a = 2;
        }
        void Button2Click(object sender, EventArgs e)
        {
            a = 3;
        }
        void Button3Click(object sender, EventArgs e)
        {
            a =4;
        }
        void TextBox3TextChanged(object sender, EventArgs e)
        {
   
        }
        void TextBox5TextChanged(object sender, EventArgs e)
        {
   
        }

       
    }
}


Inilah contoh programnya yang saya jalankan..
1.adalah awal
2.program yang sedang dijalankan.










 untuk jelasnya liat di http://youtu.be/VX3Sp_AeS_s

 ok demikianlah program yang telah saya buat terima kasih :-)
see you next time

asalammualaikum wr.wb

Tidak ada komentar:

Posting Komentar