question about rectangle?

  • Thread starter Thread starter AsuWoo
  • Start date Start date
A

AsuWoo

you are given two rectangles, each defined by an upper left(UL) corner and a
low right(LR)corner,Both rectangles' edges will always be parrallel to the x
or y axis ,Write a window program with c# that user can use mouse to draw
the rectangle add the program will determines whether the two rectangles
overlap. For convenience, you may use the following structs:
Struct point{
Int x;
Int y;
}
Struct rect{
struct point UL;
struct point LR;
}
The function prototype is As following:
int overlap(struct rect A,struct rect B);
 
Um, this sounds like home work or some test :P
Note all triangles will be like this one, but the position may wary.
If you get stuck, ask specific problems.

UL
Y |\
| | \
| |__\LR
|
|_______x
 
I want to know the best way to draw rectangle on form,
I write some code in mouseup() and mousemove(),mousedown(),
but it not work, i cant save the rectangle's data
 
Well, you only need two points to know the rectangle since you can
calculate the third one.
UL and LR. The corner point (CP) will be (UL.x, LR,y).

Drawing the triangle can be done by DrawLine between each of the points
(UL, LR), (LR, CP), (CP, UL)
Capture the UL on mousedown, and use mousemove coordinates for LR until
mouseup.

If you call Invalidate() after mousemove events/mouseup you can erase the
old triangle by drawing it using the background color (you need the old LR
for that) before drawing the new triangle.
 
thanx
i will try
"Morten Wennevik" <[email protected]>
??????:oprykoc5t8hntkfz@localhost...
Well, you only need two points to know the rectangle since you can
calculate the third one.
UL and LR. The corner point (CP) will be (UL.x, LR,y).

Drawing the triangle can be done by DrawLine between each of the points
(UL, LR), (LR, CP), (CP, UL)
Capture the UL on mousedown, and use mousemove coordinates for LR until
mouseup.

If you call Invalidate() after mousemove events/mouseup you can erase the
old triangle by drawing it using the background color (you need the old LR
for that) before drawing the new triangle.
 
Back
Top