Window Display
Public Class Form1
Private form_details As New Facet
Private action_class As New Dymetric
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
form_details.formFeatures(sender)
End Sub
Private Sub Form1_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint
form_details.decorateButtonArea(sender, e)
action_class.decideAction(sender, Me.CreateGraphics(), form_details.CLICK_OCCURRED)
form_details.CLICK_OCCURRED = False
End Sub
End Class
Facet class
Public Class Facet
Dim screen_rect As Rectangle
Public CLICK_OCCURRED As Boolean = False
Public Sub formFeatures(sender As Object)
screen_rect = Screen.PrimaryScreen.Bounds
sender.SetDesktopBounds(0, 0, screen_rect.Width, screen_rect.Height)
sender.Text = "useOfMaths.com"
sender.BackColor = System.Drawing.Color.LightGray
Dim path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().CodeBase)
path = New Uri(path).LocalPath
Try
sender.Icon = New Icon(path & "\useOfMaths.ico")
Catch ex As System.IO.FileNotFoundException
End Try
Dim response_btn As New Button()
response_btn.BackColor = System.Drawing.Color.Magenta
response_btn.ForeColor = System.Drawing.Color.Blue
response_btn.Name = "response_btn"
response_btn.SetBounds(CInt(Math.Round(screen_rect.Width / 2)) - 50, 5, 100, 40)
response_btn.Text = "Move"
sender.Controls.Add(response_btn)
AddHandler response_btn.Click, AddressOf response_btn_Click
End Sub
Public Sub decorateButtonArea(sender As Object, e As PaintEventArgs)
Dim pencil As New System.Drawing.Pen(System.Drawing.Color.Black)
pencil.DashStyle = Drawing2D.DashStyle.DashDot
pencil.Width = 5
e.Graphics.DrawLine(pencil, 0, 50, sender.Width, 50)
pencil.Dispose()
Dim paint_brush As New System.Drawing.SolidBrush(System.Drawing.Color.Pink)
e.Graphics.FillRectangle(paint_brush, 0, 0, sender.Width, 50)
paint_brush.Dispose()
End Sub
Public Sub response_btn_Click(sender As Object, e As EventArgs)
CLICK_OCCURRED = True
sender.Refresh()
End Sub
End Class
Dymetric class
Public Class Dymetric
Private move_body As New MovingBody
Private do_simulation = False
Public Sub decideAction(sender As Object, g As Graphics, click_check As Boolean)
If do_simulation And click_check Then
move_body.play(sender, g)
do_simulation = False
Else
move_body.prep(sender, g)
do_simulation = True
End If
End Sub
End Class
VB.Net code for MovingBody class
Public Class MovingBody
Private x, y As Integer
Private previous_x As Integer = 0
Private previous_y As Integer = 0
Private Const ballDIAMETER = 80
Dim ball_colour As New System.Drawing.SolidBrush(System.Drawing.Color.Yellow)
Dim bg_colour As New System.Drawing.SolidBrush(System.Drawing.Color.LightGray)
Public Sub prep(sender As Object, g As Graphics)
x = 10
y = Math.Round(sender.Height / 2)
If previous_x > 0 Then
g.FillEllipse(bg_colour, previous_x, previous_y, ballDIAMETER, ballDIAMETER)
End If
g.FillEllipse(ball_colour, x, y, ballDIAMETER, ballDIAMETER)
previous_x = x
previous_y = y
End Sub
Public Sub play(sender As Object, g As Graphics)
Do While x < sender.Width - ballDIAMETER
g.FillEllipse(bg_colour, previous_x, previous_y, ballDIAMETER, ballDIAMETER)
g.FillEllipse(ball_colour, x, y, ballDIAMETER, ballDIAMETER)
previous_x = x
x += 10
Threading.Thread.Sleep(50)
Loop
End Sub
End Class