Selasa, 16 Desember 2008

Draw pollygon di Visual C#

Kali ini Teknik menggambar Pollygon jangan lupa ciptakan class
using System.Drawing.Drawing2D;
buat even handler di form dengan even paint ciptakan objek graphic

LISTING Program Lengkapnya


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;


namespace mainform

{


public
partial
class
Form1 : Form

{


public Form1()

{

InitializeComponent();

CenterToScreen();

SetStyle(ControlStyles.ResizeRedraw, true);

}



private
void Form1_Paint(object sender, PaintEventArgs e)

{


//ciptakan graphic objek

Graphics g = this.CreateGraphics();

Brush b = new
SolidBrush(Color.Maroon);

Point[] points = new
Point[]

{

new
Point(10, 10),

new
Point(10, 100),

new
Point(50, 65),

new
Point(100, 100),

new
Point(85, 40)}; // Notice the braces, as used in structures

g.FillPolygon(b, points);

}

}

}


Coba jalankan dengan klik debug atau tekan tombol F5




Tidak ada komentar: