-2

quote from other post:

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

This is awful! I have to put in a hundred equidistant points!

Draw polygon to screen.

e->Graphics->FillPolygon( blueBrush, curvePoints );

I have tried many things:

array<Point,2>^ aPoints;
//Points tabPoints[10][10];//= new Points[10][10];
Points = gcnew array<Point,2>(10,10);
//init des tableaux 

for (int i = 0;i<10;i++)
{
    for(int j =0;j<10;j++)
    {
    //tabPoints[i][j].pX =i*10;
    //tabPoints[i][j].pY = j * 10;
    // = new Points(i*10,j*10);
    aPoints[i,j]= new Point(i*20,j*20);
    }
}  

None of them work!

Sandip Armal Patil
  • 6,241
  • 21
  • 93
  • 160
Sassinak
  • 95
  • 2
  • 12

2 Answers2

1

What you've got now isn't a 100 point array, it's a 10x10 2D array. Try gcnew array<Point>(100), and you'll be able to pass that to FillPolygon.

David Yaw
  • 27,383
  • 4
  • 60
  • 93
  • @Ben Voigt 's answer was the right one, thanks. It turned out I needn't FillPolygon after all; a 2d array does just fine, with fillEllipse for every point in the array. I am still learning how to get around in this forum: how do I mark his answer as the right one ? – Sassinak Sep 11 '12 at 00:47
  • He didn't post an answer, he posted a comment. The convention seems to be to ask him to post it as an answer, which I've just done. – David Yaw Sep 11 '12 at 02:39
1

A 2-D array isn't necessarily what you want, but you can make your current code work with just one minor change:

  • Get rid of new inside the loop. You want a Point value, not a pointer to one.

MSDN had that part right already.

Ben Voigt
  • 277,958
  • 43
  • 419
  • 720