DrawPolygon method - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


DrawPolygon method

SchwarzeneggerSchwarzenegger Posts: 10Member
Hello dear programmers!
Ok :

I'm creating a "paintBrush" (like windows have):
I want to create a polyline (what you can call "FreeHand") , anyway, I understood I suppose to have a dynamic array of Points (for instence:

Point[] curvePoints = new Point[];

But I get the following error:

Array creation must have array size or array initializer

Which means I'm doing something wrong in the defintion (I want a dynamic array) How do I define it?

Also You will have my gradedute, if you can show me how should I continue to create the poly line.. (what should I put in mouse move, down , up?)

Sincirly yours,



  • IDKIDK Posts: 1,784Member
    This is how it's done:

    Point[] curvePoints = new Point[0];

    in the mousedown event, add a point like this:

    addPoint(curvePoints, new Point(e.X,e.Y));

    You have to define the addPoint func to add a point.
    (you could use a System.Collections.Array, wich have it predefined, but it lowers performance...)

    The add func should look like this: (written from head...)
    add(params Point[] p){
    Point[] tmp = new Point[curvePoints.Length + p.Length];
    curvedPoints.CopyTo(tmp, 0);
    p.CopyTo(tmp, curvedPoints.Length);
    curvedPoints = tmp;

    I don't got time to write anymore...
    Have fun with this code

    Happy coding wishes
    the one and only
    [b]Niklas Ulvinge[/b] [white]aka [b]IDK[/b][/white]

  • SchwarzeneggerSchwarzenegger Posts: 10Member
    Hi Niklas .

    I just wanted to say thanks for your help (To be honest I havent managed to create the FreeHand, I just dont know what to do...)

    Anyway thanks for your help..

Sign In or Register to comment.