Wrox Programmer Forums
|
BOOK: Ivor Horton's Beginning Visual C++ 2008 ISBN: 978-0-470-22590-5
This is the forum to discuss the Wrox book Ivor Horton's Beginning Visual C++ 2008 by Ivor Horton; ISBN: 9780470225905
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Ivor Horton's Beginning Visual C++ 2008 ISBN: 978-0-470-22590-5 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 24th, 2010, 09:11 PM
Authorized User
 
Join Date: Feb 2010
Posts: 11
Thanks: 1
Thanked 0 Times in 0 Posts
Default Line Move in ch16 CLRSketcher

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.

Last edited by fortran_ii; June 24th, 2010 at 09:13 PM..





Similar Threads
Thread Thread Starter Forum Replies Last Post
How do you move the mouse outside the form and to move diagonally? fangzhien Visual Studio 2005 0 July 28th, 2009 10:06 PM
Ch16 PasswordRecovery won't email smiller BOOK: Professional ASP.NET 2.0 and Special Edition; ISBN: 978-0-7645-7610-2; ISBN: 978-0-470-04178-9 0 October 11th, 2006 03:59 PM
Membership & Role Management - Ch16 Carl Grainger BOOK: Professional ASP.NET 2.0 and Special Edition; ISBN: 978-0-7645-7610-2; ISBN: 978-0-470-04178-9 1 January 6th, 2006 05:44 AM
view forum in ch16?!! the world BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 2 December 22nd, 2005 08:28 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.