Assalamualaikum sahabat nah ini merupakan lanjutan dari program paint sebelumnya hanya di tambah untuk menampilkan panjang garis X,Y dan panjang totalnya ,semoga bermanfaat
> buka microsoftvisual c# 2010
> new project
ok kita buat programnya :)
ini tampilann form program yang saya buat
> buka microsoftvisual c# 2010
> new project
ok kita buat programnya :)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
private Graphics
og;
private bool gambar =
false, dragnode = false;
private int cX, cy,
x, y, dx, dy;
private double dxy;
private int m = 0, mu
= 0;
Color tia;
int diameter = 20;
public Form1()
{
InitializeComponent();
tia = Color.BlueViolet;
}
private void
panel1_Paint(object sender, PaintEventArgs e)
{
}
private void
Form1_Load(object sender, EventArgs e)
{
og = panel1.CreateGraphics();
}
private void
panel1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
gambar = true;
m++;
}
cX = e.X;
cy = e.Y;
dragnode = true;
}
private void
button1_Click(object sender, EventArgs e)
{
og.Clear(Color.White);
}
private void
button1_MouseClick(object sender, MouseEventArgs e)
{
if (gambar == true)
{
x = e.X;
y = e.Y;
dx = e.X - cX;
dy = cy - e.X;
if (mu == 1)
{
og.Clear(this.BackColor);
og.DrawLine(new Pen(Color.BlueViolet), cX, cy, e.X, e.Y);
}
else if
(mu == 2)
{
og.DrawEllipse(new Pen(Color.BlueViolet),
cX, cy, dx, dy);
}
else if
(mu == 3)
{
og.DrawRectangle(new Pen(Color.Blue),
cX, cy, dx, dy);
}
}
}
private void
panel1_MouseMove(object sender, MouseEventArgs e)
{
textBox1.Text = Convert.ToString(dx);
textBox2.Text = Convert.ToString(dy);
dxy = Math.Sqrt(dx + dx) + (dy + dy);
textBox3.Text = Convert.ToString(dxy);
if (gambar == true)
{
x = e.X;
y = e.Y;
dx = e.X - cX;
dy = e.Y-cy;
og.Clear(panel1.BackColor);
if (mu == 1)
{
og.DrawLine(new Pen(tia),
cX, cy, e.X, e.Y);
}
else if
(mu == 2)
{
og.DrawEllipse(new Pen(tia), cX, cy, dx, dy);
}
else
if (mu == 3)
{
og.DrawRectangle(new Pen(tia),cX,cy,dx,dy);
}
}
}
private void
button8_Click(object sender, EventArgs e)
{
mu = 1;
}
private void
panel1_MouseUp(object sender, MouseEventArgs e)
{
gambar = false;
}
private void
textBox1_TextChanged(object sender, EventArgs e)
{
}
private void button9_Click(object
sender, EventArgs e)
{
mu = 2;
}
private void
button10_Click(object sender, EventArgs e)
{
mu = 3;
}
private void
button2_Click(object sender, EventArgs e)
{
tia = Color.Red;
}
private void
button7_Click(object sender, EventArgs e)
{
tia = Color.Black;
}
private void
button3_Click(object sender, EventArgs e)
{
tia = Color.Yellow;
}
private void
button6_Click(object sender, EventArgs e)
{
tia = Color.Green;
}
private void
button5_Click(object sender, EventArgs e)
{
tia = Color.Blue;
}
private void
button4_Click(object sender, EventArgs e)
{
tia = Color.Magenta;
}
}
}
selamat mencoba sahabat
kunjungi juga TIA ARIYANTI ON YOUTUBE
Comments
Post a Comment