Howdy, Stranger!

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

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

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,

Rotem



Comments

  • 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...)
    [code]
    add(params Point[] p){
    Point[] tmp = new Point[curvePoints.Length + p.Length];
    curvedPoints.CopyTo(tmp, 0);
    p.CopyTo(tmp, curvedPoints.Length);
    curvedPoints = tmp;
    }[/code]

    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..

    Rotem
Sign In or Register to comment.