1Public Class Form1
2 Dim gfxobj As System.Drawing.Graphics
3 Dim count As Integer
4 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _
5 Handles MyBase.Load
6 gfxobj = pnlDraw.CreateGraphics()
7 Timer1.Enabled = False
8 lblSpeed.Text = "Current Fill Speed = " & trbSpeed.Value & " ms"
9 count = 0
10 End Sub
11 Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Resize
12 If Not gfxobj Is Nothing Then
13 gfxobj.Dispose()
14 End If
15 gfxobj = pnlDraw.CreateGraphics()
16 gfxobj.Clear(pnlDraw.BackColor)
17 End Sub
18 Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
19 Dim newBrush As Brush
20 newBrush = New SolidBrush(Color.Blue)
21 If count < 180 Then
22 gfxobj.FillRectangle(newBrush, 31, 298 - count, 98, 1)
23 count = count + 1
24 Else
25 Timer1.Enabled = False
26 StopWaterFall()
27 End If
28 End Sub
29 Private Sub trbSpeed_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles trbSpeed.Scroll
30 Timer1.Interval = trbSpeed.Value
31 lblSpeed.Text = "Current Fill Speed = " & trbSpeed.Value & " ms"
32 End Sub
33 Sub DrawBeaker()
34 Dim newPen = New Pen(Color.White, 2)
35 gfxobj.DrawLine(newPen, 30, 300, 130, 300)
36 gfxobj.DrawLine(newPen, 30, 100, 30, 300)
37 gfxobj.DrawLine(newPen, 130, 100, 130, 300)
38 End Sub
39 Sub DrawWaterFall()
40 Dim newBrush As Brush
41 newBrush = New SolidBrush(Color.Blue)
42 gfxobj.FillRectangle(newBrush, 66, 48, 23, 251)
43 End Sub
44 Sub CleanWaterFall()
45 Dim newBrush As Brush
46 newBrush = New SolidBrush(Color.Black)
47 gfxobj.FillRectangle(newBrush, 66, 48, 23, 251)
48 End Sub
49 Sub StopWaterFall()
50 Dim newBrush As Brush
51 newBrush = New SolidBrush(Color.Black)
52 gfxobj.FillRectangle(newBrush, 66, 48, 23, 71)
53 End Sub
54 Sub CleanWater()
55 Dim newBrush As Brush
56 newBrush = New SolidBrush(Color.Black)
57 gfxobj.FillRectangle(newBrush, 31, 118, 98, 181)
58 End Sub
59 Private Sub btnRestart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRestart.Click
60 DrawBeaker()
61 CleanWater()
62 DrawWaterFall()
63 count = 0
64 Me.Timer1.Enabled = True
65 End Sub
66End Class
67
2 Dim gfxobj As System.Drawing.Graphics
3 Dim count As Integer
4 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _
5 Handles MyBase.Load
6 gfxobj = pnlDraw.CreateGraphics()
7 Timer1.Enabled = False
8 lblSpeed.Text = "Current Fill Speed = " & trbSpeed.Value & " ms"
9 count = 0
10 End Sub
11 Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Resize
12 If Not gfxobj Is Nothing Then
13 gfxobj.Dispose()
14 End If
15 gfxobj = pnlDraw.CreateGraphics()
16 gfxobj.Clear(pnlDraw.BackColor)
17 End Sub
18 Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
19 Dim newBrush As Brush
20 newBrush = New SolidBrush(Color.Blue)
21 If count < 180 Then
22 gfxobj.FillRectangle(newBrush, 31, 298 - count, 98, 1)
23 count = count + 1
24 Else
25 Timer1.Enabled = False
26 StopWaterFall()
27 End If
28 End Sub
29 Private Sub trbSpeed_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles trbSpeed.Scroll
30 Timer1.Interval = trbSpeed.Value
31 lblSpeed.Text = "Current Fill Speed = " & trbSpeed.Value & " ms"
32 End Sub
33 Sub DrawBeaker()
34 Dim newPen = New Pen(Color.White, 2)
35 gfxobj.DrawLine(newPen, 30, 300, 130, 300)
36 gfxobj.DrawLine(newPen, 30, 100, 30, 300)
37 gfxobj.DrawLine(newPen, 130, 100, 130, 300)
38 End Sub
39 Sub DrawWaterFall()
40 Dim newBrush As Brush
41 newBrush = New SolidBrush(Color.Blue)
42 gfxobj.FillRectangle(newBrush, 66, 48, 23, 251)
43 End Sub
44 Sub CleanWaterFall()
45 Dim newBrush As Brush
46 newBrush = New SolidBrush(Color.Black)
47 gfxobj.FillRectangle(newBrush, 66, 48, 23, 251)
48 End Sub
49 Sub StopWaterFall()
50 Dim newBrush As Brush
51 newBrush = New SolidBrush(Color.Black)
52 gfxobj.FillRectangle(newBrush, 66, 48, 23, 71)
53 End Sub
54 Sub CleanWater()
55 Dim newBrush As Brush
56 newBrush = New SolidBrush(Color.Black)
57 gfxobj.FillRectangle(newBrush, 31, 118, 98, 181)
58 End Sub
59 Private Sub btnRestart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRestart.Click
60 DrawBeaker()
61 CleanWater()
62 DrawWaterFall()
63 count = 0
64 Me.Timer1.Enabled = True
65 End Sub
66End Class
67
来源:https://www.cnblogs.com/aspxphpjsprb/archive/2007/11/23/969376.html