Public Class MainForm
Private Sub MainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim startX As Integer = (Screen.PrimaryScreen.WorkingArea.Width \ 2) - (Me.Width \ 2)
Dim starty As Integer = 50
Dim startPoint As New Point(startX, starty)
Me.Location = startPoint
End Sub
Private Sub MainForm_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
DrawLines()
End Sub
Private Sub MainForm_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
DrawLines()
End Sub
Private Sub DrawLines()
For i As Integer = 1 To 100
Randomize()
'create a random object and generate random line points
Dim randomGen As New Random
Dim intRandX As Integer = randomGen.Next(10, Me.ClientSize.Width - 10)
Dim intRandY As Integer = randomGen.Next(10, Me.ClientSize.Height - 10)
Dim intRandXX As Integer = randomGen.Next(10, Me.ClientSize.Width - 10)
Dim intRandYY As Integer = randomGen.Next(10, Me.ClientSize.Height - 10)
'create a graphics object to draw on the form
Dim formGraphics As Graphics
formGraphics = Me.CreateGraphics
'make a rgba(alpha,red,green,blue) pen with random colors, size, and dash style
Dim randAlpha As Integer = randomGen.Next(5, 255)
Dim randRed As Integer = randomGen.Next(0, 255)
Dim randBlue As Integer = randomGen.Next(0, 255)
Dim randGreen As Integer = randomGen.Next(0, 255)
Dim randSize As Integer = randomGen.Next(1, 10)
Dim randPen As New Pen(Color.FromArgb(randAlpha, randRed, randGreen, randBlue), randSize)
randPen.StartCap = Drawing2D.LineCap.Round
randPen.EndCap = Drawing2D.LineCap.Round
'pick dash style
Dim dashStyle As Integer = randomGen.Next(1, 5)
Select Case dashStyle
Case 1
randPen.DashStyle = Drawing2D.DashStyle.Solid
Case 2
randPen.DashStyle = Drawing2D.DashStyle.Dash
Case 3
randPen.DashStyle = Drawing2D.DashStyle.DashDot
Case 4
randPen.DashStyle = Drawing2D.DashStyle.DashDotDot
Case 5
randPen.DashStyle = Drawing2D.DashStyle.Dot
End Select
'draw line
formGraphics.DrawLine(randPen, intRandX, intRandY, intRandXX, intRandYY)
'dispose of graphics object
formGraphics.Dispose()
Next i
'clear the form
Me.Invalidate()
End Sub
End Class