Click here to Skip to main content
16,017,986 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi frds,

am new one to c#.Now am troubling to create custom control.preciously create polygon controls like traingle,hexagon,pentagon and so on.pls help me to break my trouble.It will help to my carrier.pls help me

thanks in advance
Posted
Updated 1-Nov-13 8:38am
v3
Comments
Kenneth Haugland 1-Nov-13 5:10am    
I cant really tell what your problem is, could you explain please? What polygon and what controls?
nixonanand 1-Nov-13 14:36pm    
Polygon means above three connected lines.now i want to create custom control like triangle,hexagon,pentagon and so on.now i think u understood my question.can u help me
BillWoodruff 1-Nov-13 6:05am    
Is this a question about WinForms ?

What have you tried so far ?

If you mean "how do I create a custom control that is polygonal rather than rectangular?"
Then it's surprisingly easy: in it's constructor set the Region Property to the shape you want:
C#
GraphicsPath path = new GraphicsPath();
path.AddLines(new Point[] { new Point(0,0), new Point(Width, 0), new Point(Width / 2, Height), new Point(0,0)});
Region = new Region(path);
Creates a triangle, for example.
 
Share this answer
 
Below is the sample how to draw a Polygon by using c#.


public void DrawPolygonPoint(PaintEventArgs e)
{

    // Create pen.
    Pen blackPen = new Pen(Color.Black, 3);

    // Create points that define polygon.
    Point point1 = new Point(50,  50);
    Point point2 = new Point(100,  25);
    Point point3 = new Point(200,   5);
    Point point4 = new Point(250,  50);
    Point point5 = new Point(300, 100);
    Point point6 = new Point(350, 200);
    Point point7 = new Point(250, 250);
    Point[] curvePoints =
             {
                 point1,
                 point2,
                 point3,
                 point4,
                 point5,
                 point6,
                 point7
             };

    // Draw polygon to screen.
    e.Graphics.DrawPolygon(blackPen, curvePoints);
}


For more info :Polygon

Another link : SOF

I hope this will help to you.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900