0

Hi,

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

protected override void OnPaint(PaintEventArgs pe)
{

                  

   // Create pen.
   Pen blackPen = new Pen(Color.Black, 3);
   // Create points that define polygon.
   Point point1 = new Point(0, 0);
   Point point2 = new Point(0, 50);
   Point point3 = new Point(150, 50);
   Point point7 = new Point(70, 0);
   Point[] curvePoints =
   {
      point1,
      point2,
      point3,
      point7
   };
   // Draw polygon to screen.
   pe.Graphics.DrawPolygon(blackPen, curvePoints);
         
 
}

Then in my main, I've initialize as below and I created an instance of it

PolygonShape poliA = new PolygonShape();
poliA.Width = 100; //(this width and height turn out to be a rectangle)
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?

3
Contributors
4
Replies
5
Views
9 Years
Discussion Span
Last Post by karhong
0

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)

0

Hi,

My advice is that you in the constructor of the class PoligonShape should recieve an array of points and a Pen. Add a method called Paint that method shoud recive a Form
and you assign the grafic object like this:

Grafic g = form.CreateGrafic();//form is the parameter of the Paint method

Regards,
Camilo

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.