我是C ++的新手。我正在使用Visual Studio Professional 2010.我学会了绘制线条,但这次我需要绘制填充多边形。我画线的方式如下:
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 );}
如何使用与我目前学到的技术类似的方法绘制填充多边形?
答案 0 :(得分:1)
致电Graphics.FillPolygon()
。您需要画笔而不是笔,并且必须将您的点放入点数组Point[]
。
来自MSDN的示例代码如下:
// 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 );