Tugas membuat aplikasi menggambar
dan menghitung panjang sebuah garis paint pada SharpDevelop
1. Runing Aplikasi Sharp develop.
2. Klik New Solution.
3. Pilih Windows Aplication, beri nama file, dan tempat penyimpanannya.
Kemudian klik Create.
4. Setelah muncul gambar ini pilih lah Design.
55. Kemudian akan muncul lembar kerja seperti di bawah ini,kita bisa
mengedit tampilan sesuai kreativitas kita sendiri ,caranya adalah pilih windows
forms di sebelah kiri kemudian pilih control type yang digunakan sesuai
kebutuhan dengan cara di seret ke layoutnya.propertiesnya bisa di ganti dengan
sesuai yang kita inginkan,propertienya berada di sebelah kanan .
Control type yang kita butuhkan adalah :
4 label
8 button
3 textbox
1 panel
Contoh designnya seperti ini:
6. Setelah Kita membuat design di Atas kita akan membuat program nya.
Ketikan programnya seperti dibawah ini :
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Paint_Iwan
{
/// <summary>
/// Description of MainForm.
/// </summary>
public partial class MainForm : Form
{
private Graphics objgraphic;
private bool gambar = false, dragmode = false;
private int X1, Y1, x, y, X2, Y2;
private double xy;
private int loop=0, line=0, warna=0;
public MainForm()
{
//
// The InitializeComponent() call is required for Windows Forms designer support.
//
InitializeComponent();
//
// TODO: Add constructor code after the InitializeComponent() call.
//
}
private void MainFormLoad(object sender, EventArgs e)
{
objgraphic = panel1.CreateGraphics();
}
private void Panel1MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
gambar = true;
loop++;
}
X1 = e.X;
Y1 = e.Y;
dragmode = true;
}
private void Panel1MouseClick(object sender, MouseEventArgs e)
{
if (gambar == true)
{
x = e.X;
y = e.Y;
X2 = e.X - X1;
Y2 = Y1 - e.Y;
if (line == 1)
{
if (warna == 1)
{
objgraphic.DrawLine(new Pen(Color.Black), X1, Y1, e.X, e.Y);
}
else if (warna == 2)
{
objgraphic.DrawLine(new Pen(Color.Red), X1, Y1, e.X, e.Y);
}
else if (warna == 3)
{
objgraphic.DrawLine(new Pen(Color.Blue), X1, Y1, e.X, e.Y);
}
else if (warna == 4)
{
objgraphic.DrawLine(new Pen(Color.Yellow), X1, Y1, e.X, e.Y);
}
else if (warna == 5)
{
objgraphic.DrawLine(new Pen(Color.Lime), X1, Y1, e.X, e.Y);
}
else { MessageBox.Show("PILIH WARNA"); }
}
else { MessageBox.Show("KLICK TOMBOL LINE"); }
}
}
private void Panel1MouseMove(object sender, MouseEventArgs e)
{
textBox1.Text = Convert.ToString(X2);
textBox2.Text = Convert.ToString(Y2);
xy = Math.Sqrt((X2 * X2) + (Y2 * Y2));
textBox3.Text = Convert.ToString(xy);
}
private void Button1Click(object sender, EventArgs e)
{
this.Refresh();
textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";
}
private void HitamClick(object sender, EventArgs e)
{
warna = 1;
}
private void MerahClick(object sender, EventArgs e)
{
warna =2;
}
private void BiruClick(object sender, EventArgs e)
{
warna = 3;
}
private void KuningClick(object sender, EventArgs e)
{
warna = 4;
}
private void HijauClick(object sender, EventArgs e)
{
warna = 5;
}
private void Button2Click(object sender, EventArgs e)
{
Close();
}
void Button3Click(object sender, EventArgs e)
{
line =1;
}
}
}
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Paint_Iwan
{
/// <summary>
/// Description of MainForm.
/// </summary>
public partial class MainForm : Form
{
private Graphics objgraphic;
private bool gambar = false, dragmode = false;
private int X1, Y1, x, y, X2, Y2;
private double xy;
private int loop=0, line=0, warna=0;
public MainForm()
{
//
// The InitializeComponent() call is required for Windows Forms designer support.
//
InitializeComponent();
//
// TODO: Add constructor code after the InitializeComponent() call.
//
}
private void MainFormLoad(object sender, EventArgs e)
{
objgraphic = panel1.CreateGraphics();
}
private void Panel1MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
gambar = true;
loop++;
}
X1 = e.X;
Y1 = e.Y;
dragmode = true;
}
private void Panel1MouseClick(object sender, MouseEventArgs e)
{
if (gambar == true)
{
x = e.X;
y = e.Y;
X2 = e.X - X1;
Y2 = Y1 - e.Y;
if (line == 1)
{
if (warna == 1)
{
objgraphic.DrawLine(new Pen(Color.Black), X1, Y1, e.X, e.Y);
}
else if (warna == 2)
{
objgraphic.DrawLine(new Pen(Color.Red), X1, Y1, e.X, e.Y);
}
else if (warna == 3)
{
objgraphic.DrawLine(new Pen(Color.Blue), X1, Y1, e.X, e.Y);
}
else if (warna == 4)
{
objgraphic.DrawLine(new Pen(Color.Yellow), X1, Y1, e.X, e.Y);
}
else if (warna == 5)
{
objgraphic.DrawLine(new Pen(Color.Lime), X1, Y1, e.X, e.Y);
}
else { MessageBox.Show("PILIH WARNA"); }
}
else { MessageBox.Show("KLICK TOMBOL LINE"); }
}
}
private void Panel1MouseMove(object sender, MouseEventArgs e)
{
textBox1.Text = Convert.ToString(X2);
textBox2.Text = Convert.ToString(Y2);
xy = Math.Sqrt((X2 * X2) + (Y2 * Y2));
textBox3.Text = Convert.ToString(xy);
}
private void Button1Click(object sender, EventArgs e)
{
this.Refresh();
textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";
}
private void HitamClick(object sender, EventArgs e)
{
warna = 1;
}
private void MerahClick(object sender, EventArgs e)
{
warna =2;
}
private void BiruClick(object sender, EventArgs e)
{
warna = 3;
}
private void KuningClick(object sender, EventArgs e)
{
warna = 4;
}
private void HijauClick(object sender, EventArgs e)
{
warna = 5;
}
private void Button2Click(object sender, EventArgs e)
{
Close();
}
void Button3Click(object sender, EventArgs e)
{
line =1;
}
}
}
7. Setelah selesai kemudian run programnya.
8. Tampilannya akan seperti ini :
Untuk
Lebih Jelas lagi Kunjungi YouTube saya :
Sampai Jumpa di
Tugas Berikutnya …………