Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / CLR / October 2005

Tip: Looking for answers? Try searching our database.

Rectangle class

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
bryan - 21 Oct 2005 20:55 GMT
try this (C# syntax for the example)

Rectangle rect = new Rectangle( 1,1,3,3); // make a rectangle at 1,1 that is
3 wide and 3 high.

Debug.Assert (rect.Left == 1); // true
Debug.Assert (rect.Top == 1); // true

// right and bottom should be 3,3

Debug.Assert (rect.Right == 3); // FALSE
Debug.Assert (rect.Bottom == 3); // FALSE ?? huh

Debug.Assert (rect.Right == 4); // true - what gives?
Debug.Assert (rect.Bottom == 4); // true

Debug.Assert(rect.Contains(1,1)); // true
Debug.Assert(rect.Contains(3,3)); // true
Debug.Assert(rect.Contains(4,4)); // FALSE - hmmm

BUT if we adjust the contructor to give us the right and bottom we expect,
the rectangle will no longer Contain the correct pixels!

Rectangle rect = new Rectangle( 1,1,3-1,3-1); // make a rectangle at 1,1
that is 3 wide and 3 high.

Debug.Assert (rect.Right == 3); // true
Debug.Assert (rect.Bottom == 3); // true

BUT -

Debug.Assert(rect.Contains(3,3)); // FALSE
Mattias Sjögren - 21 Oct 2005 22:03 GMT
bryan,

First of all, this isn't really a CLR related question.
microsoft.public.dotnet.framework.drawing is a better group for
discussing GDI+ related matters.

Second, there's a good discussion about why the Win32 RECT is endpoint
exclusive here (it's relevant for the .NET Rectangle too).

http://blogs.msdn.com/oldnewthing/archive/2004/02/18/75652.aspx

Mattias

Signature

Mattias Sjögren [MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.