Membuat Aplikasi Paint Sederhana

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

Membuat Aplikasi Paint Sederhana menggunakan SharpDevelop

Source codenya:
/*
* Created by SharpDevelop.
* User: DANI
* Date: 30/05/2015
* Time: 0:17
*
* 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 paint
{
/// <summary>
/// Description of MainForm.
/// </summary>
public partial class MainForm : Form
{
private Graphics paint;
private int ukuran = 5;
private int x1, y1, x2, y2, a,b;
private double luas;
private Boolean picture;
private int titik1 = 0, titik2 = 0;
private Color warna;
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)
{
paint = panel1.CreateGraphics();
}
void Panel1MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
picture = true;
}
x1 = e.X;
y1 = e.Y;
}

void Panel1MouseMove(object sender, MouseEventArgs e)


{
if ( picture == true )
{
a = e.X;
b = e.Y;
panel1.Refresh();
paint.DrawLine( new Pen (warna), x1, y1, e.X, e.Y );
}
}
void Panel1MouseUp(object sender, MouseEventArgs e)
{
x2 = e.X - x1;
y2 = e.Y - y1;
luas = Math.Sqrt ( x2 + x2 ) + ( y2 + y2 );
textBox1.Text = Convert.ToString(x2);
textBox2.Text = Convert.ToString(y2);
textBox3.Text = Convert.ToString(luas);
picture = false;
}
void Button1Click(object sender, EventArgs e)
{
warna = Color.Red;
}
void Button2Click(object sender, EventArgs e)
{
warna = Color.Yellow;
}
void Button3Click(object sender, EventArgs e)
{
warna = Color.Blue;
}
void Button4Click(object sender, EventArgs e)
{
warna = Color.Violet;

}
void Button5Click(object sender, EventArgs e)
{
warna = Color.Green;
}
void Button6Click(object sender, EventArgs e)
{
warna = Color.Black;
}
}
}

You might also like