Trouble dividing a rectangle into equal parts
Trouble dividing a rectangle into equal parts
Trouble dividing a rectangle into equal parts
Trouble dividing a rectangle into equal parts
Trouble dividing a rectangle into equal parts
Trouble dividing a rectangle into equal parts Trouble dividing a rectangle into equal parts Trouble dividing a rectangle into equal parts Trouble dividing a rectangle into equal parts Trouble dividing a rectangle into equal parts Trouble dividing a rectangle into equal parts Trouble dividing a rectangle into equal parts Trouble dividing a rectangle into equal parts
Trouble dividing a rectangle into equal parts Trouble dividing a rectangle into equal parts
Trouble dividing a rectangle into equal parts
Go Back  Xtreme Visual Basic Talk > > > Trouble dividing a rectangle into equal parts


Reply
 
Thread Tools Display Modes
  #1  
Old 07-22-2012, 09:43 PM
bonedoc bonedoc is offline
Junior Contributor
 
Join Date: Mar 2006
Posts: 376
Default Trouble dividing a rectangle into equal parts


I am drawing graphics on a print preview dialog. I am making a square around the page at the margins. I then want to draw 20 horizontal rectangles within this large rectangle. Seems simple, right?

Well, I notice something odd...This code works if I do a few rectangles. But, when I try more, the spacing never works out. I dont know what is happening. Any ideas?

Code:
        'draw large rectangle
        Dim Pen1 As New Pen(Brushes.Black)
        Dim rWidth, rHeight As Integer

        rWidth = e.MarginBounds.Right - e.MarginBounds.Left
        rHeight = e.MarginBounds.Bottom - e.MarginBounds.Top

        Dim r1 As New Rectangle(e.MarginBounds.Left, e.MarginBounds.Top, rWidth, rHeight)
        e.Graphics.DrawRectangle(Pen1, r1)

        'set 0,0 at margin bounds
        Dim Datum As Point = New Point(e.MarginBounds.Left, e.MarginBounds.Top)

        'get the size of 1/20 the rectangle from above
        Dim Bar As Size = New Size((rWidth / 20), rHeight)

        'draw a rec, starting at 0, count up tp 20.
        'each time increase x by bar width 

        For BarCount As Integer = 0 To 19
            e.Graphics.DrawRectangle(Pens.Blue, Datum.X, Datum.Y, Bar.Width, Bar.Height)
            Datum.X = Datum.X + Bar.Width 
        Next



        e.HasMorePages = False

Last edited by bonedoc; 07-22-2012 at 10:16 PM.
Reply With Quote
  #2  
Old 07-22-2012, 11:08 PM
bonedoc bonedoc is offline
Junior Contributor
 
Join Date: Mar 2006
Posts: 376
Default

Apparently, it is a rounding that happens when I divide to get the demensions ;-)
Reply With Quote
  #3  
Old 07-23-2012, 12:16 AM
passel's Avatar
passelTrouble dividing a rectangle into equal parts passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,024
Default

If it is a rounding error, perhaps use types like SizeF rather than Size, so you don't loose your fractional information.
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Trouble dividing a rectangle into equal parts
Trouble dividing a rectangle into equal parts
Trouble dividing a rectangle into equal parts Trouble dividing a rectangle into equal parts
Trouble dividing a rectangle into equal parts
Trouble dividing a rectangle into equal parts
Trouble dividing a rectangle into equal parts Trouble dividing a rectangle into equal parts Trouble dividing a rectangle into equal parts Trouble dividing a rectangle into equal parts Trouble dividing a rectangle into equal parts Trouble dividing a rectangle into equal parts Trouble dividing a rectangle into equal parts
Trouble dividing a rectangle into equal parts
Trouble dividing a rectangle into equal parts
 
Trouble dividing a rectangle into equal parts
Trouble dividing a rectangle into equal parts
 
-->