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?

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)

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

Hi, i think GraphicsPath class may also helpful

Thanks !

GraphicPath really help it ! :twisted:

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.