Torna al Thread

Imports System.Drawing.Drawing2D Public Class Form1 Private PointList As New List(Of PointF)() Private pointIndex As Integer = 0 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load SetStyle(ControlStyles.UserPaint, True) SetStyle(ControlStyles.AllPaintingInWmPaint, True) SetStyle(ControlStyles.DoubleBuffer, True) Dim pt As PointF() = New PointF() {New PointF(100, 100), New PointF(150, 150), New PointF(200, 100), New PointF(100, 100)} Dim curDist As Single = 0 Dim distance As Single = 0 For i As Integer = 0 To pt.Length - 2 Dim ptA As PointF = pt(i) Dim ptB As PointF = pt(i + 1) Dim deltaX As Single = ptB.X - ptA.X Dim deltaY As Single = ptB.Y - ptA.Y curDist = 0 distance = CSng(Math.Sqrt(Math.Pow(deltaX, 2) + Math.Pow(deltaY, 2))) While curDist < distance curDist += 1 Dim offsetX As Single = CSng((CDbl(curDist) / CDbl(distance) * CDbl(deltaX))) Dim offsetY As Single = CSng((CDbl(curDist) / CDbl(distance) * CDbl(deltaY))) PointList.Add(New PointF(ptA.X + offsetX, ptA.Y + offsetY)) End While Next End Sub Private Sub Form1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint e.Graphics.SmoothingMode = SmoothingMode.AntiAlias For i As Integer = 0 To pointIndex - 1 e.Graphics.DrawLine(Pens.Black, PointList(i).X, PointList(i).Y, PointList(i + 1).X, PointList(i + 1).Y) Next End Sub Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick If pointIndex < PointList.Count - 1 Then pointIndex += 1 Me.Refresh() End If End Sub End Class
Copyright © dotNetHell.it 2002-2024
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5