I found that the Line Move in CLR Sketecher of chapter 16, as given in the book, does not work properly.

The on-line version from wrox.com shows the same behavior. The other three element types move without problem.
The source of the problem is that the Draw function in the Line class does its drawing based on position and end. end is a Point which is a Line class variable. Its value is assigned by the Line constructor, and its value is never changed. This arrangement is unique to the Line element class.
I modified the Line class such that the problem is fixed, as shown below.
Code:
public ref class Line : Element
{
protected:
//Point end;
int deltaX, deltaY;
public:
// constructor
Line(Color color, Point start, Point end)
{
pen = gcnew Pen(color);
this->color = color;
position = start;
//this->end = end;
deltaX = end.X - start.X;
deltaY = end.Y - start.Y;
boundRect = System::Drawing::Rectangle(Math::Min(position.X, end.X),
Math::Min(position.Y, end.Y),
Math::Abs(position.X - end.X), Math::Abs(position.Y - end.Y));
// provide for lines that are horizontal or vertical
if(boundRect.Width < 2) boundRect.Width = 2;
if(boundRect.Height < 2) boundRect.Height = 2;
}
// function to draw a line
virtual void Draw(Graphics^ g) override
{
pen->Color = highlighted ? highlightColor : color;
g->TranslateTransform(safe_cast<float>(position.X),
safe_cast<float>(position.Y));
//g->DrawLine(pen, 0, 0, end.X-position.X, end.Y-position.Y);
g->DrawLine(pen, 0, 0, deltaX, deltaY);
g->ResetTransform();
}
};
I am interested to know if you (the reader of the book, reader of this posting, or author of the book) agree, or have any comments regarding this.
Thanks for reading this.