2011-10-01 58 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);