|
-
May 10th, 2012, 09:57 AM
#3
Thread Starter
Addicted Member
Re: Use Lines to draw Geometric Figures(Polygons)?
 Originally Posted by .paul.
using that link for the example, try this:
vb Code:
Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click PictureBox1.Invalidate() End Sub Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint Dim pn As New Pen(Color.Blue) Dim pt1 As New Point(30, 30) Dim pt2 As New Point(110, 100) Dim pts As Point() = {pt1, pt2} 'Stop Project(pts, PictureBox1.Width, PictureBox1.Height) e.Graphics.DrawLines(pn, pts) ' Create a pen with red color and width 3 Dim redPen As New Pen(Color.Red, 3) ' Create an array of points Dim ptsArray() As Point = {New Point(10, 20), New Point(50, 40), New Point(220, 120), New Point(120, 20)} Project(ptsArray, PictureBox1.Width, PictureBox1.Height) e.Graphics.DrawLines(redPen, ptsArray) End Sub Public Sub Project(ByRef p() As Point, ByVal viewWidth As Integer, ByVal viewHeight As Integer) Dim MinX As Integer = p.Min(Function(pt) pt.X) Dim MaxX As Integer = p.Max(Function(pt) pt.X) Dim MinY As Integer = p.Min(Function(pt) pt.Y) Dim MaxY As Integer = p.Max(Function(pt) pt.Y) Dim leftOffset As Integer = (viewWidth - (MaxX - MinX)) \ 2 Dim topOffset As Integer = (viewHeight - (MaxY - MinY)) \ 2 For x As Integer = 0 To p.GetUpperBound(0) p(x) = New Point(p(x).X + leftOffset, p(x).Y + topOffset) Next End Sub Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize PictureBox1.Invalidate() End Sub End Class
woooooooooow, awesome, awesome & Awesome! Works Perfect, just what I needed (with the correction on the second post, ofc). Thank you sooooooooooooooooo muchhhhhhhhhh! Can finally present the project to my teacher, the cherry above the cake is finally put!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|