16,552
社区成员
发帖
与我相关
我的任务
分享
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.Timer1.Enabled = True
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Static j As Long
j += 1
PictureBox1.Image = x_y(PictureBox1, j)
End Sub
Private Function x_y(ByVal pic As PictureBox, ByVal x As Long) As Bitmap
Dim b As New Bitmap(pic.Width, pic.Height)
Dim g As Graphics = Graphics.FromImage(b)
Dim c
Dim j
g.Clear(Color.White)
Dim p As New Pen(Color.Red)
p.EndCap = Drawing2D.LineCap.ArrowAnchor '指定可用线帽样式,Pen 对象以该线帽结束一段直线
g.DrawLine(p, 20, pic.Height - 20, 20, 10) '画Y轴
g.DrawLine(p, 20, pic.Height - 20, pic.Width - 20, pic.Height - 20) '画经X轴
'--------------------------------------------------
Dim i As Double
Dim bs As New SolidBrush(Color.Green)
Dim po As New Point
g.DrawString(0, Me.Font, bs, 12, pic.Height - 18) '0点
po.X = 0 '開始X位置
po.Y = pic.Height - 40 '開始Y位置
For i = 0.5 To 5 Step 0.5
g.DrawString(i, Me.Font, bs, po.X, po.Y) '数字
g.DrawLine(p, po.X + 18, po.Y + 5, po.X + 20, po.Y + 5) '点
Dim p1 As New Pen(Color.Blue) '線
p1.DashStyle = Drawing2D.DashStyle.Dash
g.DrawLine(p1, po.X + 28, po.Y + 5, pic.Width - 20, po.Y + 5)
'間隔
po.Y -= (pic.Height - 50) / 9
Next
'開始X位置
po.X = 20
'開始Y位置
po.Y = pic.Height - 20
For c = 0 To 14400 Step 1200
'数字位置
If (c / 1200) > 0 Then
g.DrawString((c / 1200) + x, Me.Font, bs, po.X - j, po.Y + 5)
end if
g.DrawLine(p, po.X, po.Y + 2, po.X, po.Y)
po.X += (pic.Width - 50) / 12
Next
Return b
End Function
End Class