开发者

How to draw filled polygon using c++?

I'm new to C++. I am using Visual studio Professional 2010. I learned to draw lines, but I need to draw filled polygon this time. The way that I drew lines is below:

private: System::Void Form1_Paint(System::Object^  sender, System::Windows::Forms::PaintEventArgs^  e) {
                Graphics ^g = e->Graphics;  //require for drawing
                g->DrawArc(Pens::Black, i-the_size/2, j-the_size/2, the_size, the_size, 0, 90 );
                g->DrawArc(Pens::Black, i+the_size/2, j+the_size/2, the_size, the_size, 180, 90 );}

How can I draw 开发者_StackOverflow中文版filled polygons using techniques similar to what I have learned so far?


Call Graphics.FillPolygon(). You will need a brush rather than a pen and you must put your points into a point array Point[].

The sample code from MSDN is like this:

// Create solid brush.
SolidBrush^ blueBrush = gcnew SolidBrush( Color::Blue );

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

// Draw polygon to screen.
e->Graphics->FillPolygon( blueBrush, curvePoints );
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜