Creating a polygon in main()

karhong

Member
Joined
Jul 13, 2008
Messages
6
Programming Experience
Beginner
Hi,

I wanted to know how do I create the exact polygon in my main form.
I've now created a class "PolygonShape" and inside there is this code(this is a shape of a trapezium):

VB.NET:
Protected Overloads Overrides Sub OnPaint(ByVal pe As PaintEventArgs)
 
    ' Create pen.
    Dim blackPen As New Pen(Color.Black, 3)
     ' Create points that define polygon.
    Dim point1 As New Point(0, 0)
    Dim point2 As New Point(0, 50)
    Dim point3 As New Point(150, 50)
    Dim point7 As New Point(70, 0)
    Dim curvePoints As Point() = {point1, point2, point3, point7}
    ' Draw polygon to screen.
    pe.Graphics.DrawPolygon(blackPen, curvePoints)
    
    
End Sub


Then in my main, I've initialize as below
VB.NET:
Dim poliA As New PolygonShape()
poliA.Width = 100
poliA.Height = 50
poliA.BackColor = Color.Azure


P/S : i know why it turn out to be rectangle... but i don't know how to make it to follow the design at top when displaying it..


PROBLEM : when i run this code, then it will come out with a rectangle shape.I've alread tried to research.. but i dont get any ways to make the shape become the shape of the trapezium. Any idea?
 
Last edited by a moderator:
For easier to understand what i'm going to do.

I wanted to make

x.Width
x.Height

to be a shape of trapezium... I'm wondering whether I'm able to put the shape into it or not (for the instance of my object)
 
Not exactly sure what your goal is...
But here's how I typically load a point array to a polygon and draw it.


VB.NET:
Dim MyPoints(0 To 3) As Point
MyPoints(0) = New Point(0, 0)
MyPoints(1) = New Point(0, 50)
MyPoints(2) = New Point(150, 50)
MyPoints(3) = New Point(70, 0)

Dim MyPath As Drawing2D.GraphicsPath = New Drawing2D.GraphicsPath
MyPath.AddPolygon(MyPoints)

Dim g As Graphics = Graphics.FromImage(MyImage) 
g.DrawPath(New Pen(Color.Black, 1), MyPath)
 
Last edited:
Back
Top