PictureBox 画坐标系 X轴为时间 可移动 有代码

little_potato 2010-04-13 01:42:54
一个Form 一个PictureBox 一个按钮 一个timer

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
j += 1
PictureBox1.Image = x_y(PictureBox1)
End Sub

Private Function x_y(ByVal pic As PictureBox) As Bitmap
Dim b As New Bitmap(pic.Width, pic.Height)
Dim g As Graphics = Graphics.FromImage(b)
'背景色
'g.Clear(Color.White)
'線色
Dim p As New Pen(Color.White)
'線様式
p.EndCap = Drawing2D.LineCap.ArrowAnchor
'X
g.DrawLine(p, 20, pic.Height - 20, 20, 10)
'Y
g.DrawLine(p, 20, pic.Height - 20, pic.Width - 20, pic.Height - 20)
'--------------------------------------------------
Dim i As Double
Dim bs As New SolidBrush(Color.Yellow)
Dim po As New Point
'0点
g.DrawString(0, Me.Font, bs, 12, pic.Height - 18)
'開始X位置
po.X = 0
'開始Y位置
po.Y = pic.Height - 40
For i = 0.5 To 5 Step 0.5
'数字
g.DrawString(i, Me.Font, bs, po.X, po.Y)
'点
g.DrawLine(p, po.X + 28, po.Y + 5, po.X + 30, po.Y + 5)
'線
Dim p1 As New Pen(Color.White)
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 = 55
'開始Y位置
po.Y = pic.Height - 20
For c = 0 To 14400 Step 1200
'数字位置
g.DrawString(c / 1200, Me.Font, bs, po.X - j, po.Y + 5)
g.DrawLine(p, po.X, po.Y + 2, po.X, po.Y)
po.X += (pic.Width - 50) / 12
Next
Return b
End Function
请教各位前辈:
想一直让x轴计数 循环部分怎么修改?
拜谢!
...全文
359 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
plm310 2010-09-02
  • 打赏
  • 举报
回复
运行不出来!
SYSSZ 2010-04-13
  • 打赏
  • 举报
回复
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

16,552

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧