2011-10-01 214 views
0

我是C++新手。我正在使用Visual Studio Professional 2010.我学会了绘制线条,但是这次我需要绘制填充的多边形。我画线的方式如下:如何使用C++绘制填充多边形?

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);} 

如何使用类似于我迄今了解到的技术绘制填充的多边形?

+1

请注意,C++和C++/CLI是不是把插入符的“图形”,然后按F1以找出它可以做同样的语言 – Zharf

+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);