blah blah blah is here! blah blah » Close

up0down
link

Hy,
I am a total newby in c# but i'm looking forward to get more knowledge of this language.

For the moment i'm trying to make a little drawing program. The concept is to draw lines, circles, rectangles etc with just 2 mouse clics. I was able to draw a line in my program as I wanted. The code I used for that was

-------------------------------------------------------

private void tekenpanel_MouseClick(object sender, MouseEventArgs e)
{
Graphics gVenster = tekenpanel.CreateGraphics();


{


if (nPunt == 0)
{
punt1 = new Point(e.X, e.Y);
nPunt++;
}

else if (nPunt == 1)
{
punt2 = new Point(e.X, e.Y);

gVenster.DrawLine(pen, punt1, punt2);
nPunt = 0;
}
}

--------------------------------------

Now i would like to do the same for a rectangle but each time I try i get errors (No overlad... cannot convert and i can't seem to get the mous coordinates linked to the width and the height of the regtancle...

For the moment I'm playing around whit this code in effort to make it work without luck at all :(

CODE FOR THE RECTANGLE------->

if (nPunt == 0)
{
punt1 = new Point(e.X, e.Y);
x = e.X;
nPunt++;
}

else if (nPunt == 1)
{
punt2 = new Point(e.X, e.Y);



Width= //starpoint -endpoint ??
Height=//???
gVenster.DrawRectangle(pen, punt1, punt2, Width, Height); //

nPunt = 0;
}
--------------------------------------

I hope one of you can help me beceause it's getting frustrated to be stucked at this point.

Thanks in advance.. Greatings Laurijn !

last answered one year ago

1 answers

up0down
link

I wrote a sample a while ago that I just updated to draw lines, rectangles and circles. have a look, the code should be pretty self explanatory, but if you have questions let me know.

http://sanity-free.org/misc/drawing.zip

Owké thankyou very much.. it was very helpfull :) !

Feedback