Home All Groups Group Topic Archive Search About

Scaling a collection of points(lines)?

Author
20 Oct 2006 9:50 PM
Craig Lucas
Im kind of new to vb.net drawing routines. Im reading a collection of 2d
points from a
proprietary file. These points are simply for drawing lines, I can draw the
lines fine using Graphics.DrawLine, but I need to scale all the lines to fit
a rectangle of a given width and height.

What is the best method to do something like this? Its also important that
the drawing retain proportion within the given rectangle.

Thanks
Craig

Author
20 Oct 2006 10:35 PM
Ryan S. Thiele
Have you tried percentages?

I placed a picture box on a form. Named it picturebox1

and used this code

Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
    'Draw rectangle
    Dim Rec As New Rectangle(0, 0, e.Graphics.ClipBounds.Width,
e.Graphics.ClipBounds.Height)
    e.Graphics.DrawRectangle(Pens.Green, Rec)

    'Draw 2 lines
    Dim p1 As New PointF(Rec.Width * 0.01, Rec.Height * 0.1) '1% of width,
10% of height
    Dim p2 As New PointF(Rec.Width * 0.8, Rec.Height * 0.9) '80% of width,
90% of height

    'Wrote out the ponts.
    Console.WriteLine(Rec.ToString & " " & p1.ToString)
    Console.WriteLine(rec.ToString & " " & p2.ToString)

    'Draw line to box
    e.Graphics.DrawLine(Pens.Blue, p1, p2)

End Sub

Private Sub Form1_Resize(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Resize
    'Code used to redraw.
    Me.PictureBox1.Invalidate()
End Sub

Does this help?
Good luck!

--
Thiele Enterprises - The Power Is In Your Hands Now!

--
"Craig Lucas" <craiglu***@tds.net> wrote in message
news:dwb_g.7608$5i7.6566@newsreading01.news.tds.net...
Im kind of new to vb.net drawing routines. Im reading a collection of 2d
points from a
proprietary file. These points are simply for drawing lines, I can draw the
lines fine using Graphics.DrawLine, but I need to scale all the lines to fit
a rectangle of a given width and height.

What is the best method to do something like this? Its also important that
the drawing retain proportion within the given rectangle.

Thanks
Craig