当前位置:编程学习 > VB >>

求助:vb画曲线

想在批pictureBox中根据数据库中的数据去画一条二维坐标图,从数据库中读取数据后怎么在PictureBox中画出坐标图?
以下是两个窗体的代码:

form1代码:

Private Sub Command1_Click()
Form2.Show
Form1.Enabled = False
End Sub

Private Sub Command2_Click()
End
End Sub

Private Sub Form_Load()

End Sub

form2代码:


Private Sub Command1_Click()
Dim i As Integer
On Error GoTo apperr
Data1.Recordset.AddNew
For i = 0 To 1
Text1(i).Text = ""
Next
savecancel
Exit Sub
apperr:
 MsgBox Err.Description
End Sub


Private Sub Command3_Click()
Form1.Enabled = True
Form2.Hide
End Sub

Private Sub Command2_Click()
Dim mynumber As String
mynumber = InputBox$("请输入水位", "水位搜索", "1000")
If mynumber <> "" Then
mynumber = "水位='" & mynumber & "'"
Data1.Recordset.FindFirst mynumber
End If
End Sub

Private Sub Command4_Click()
Dim s As String
On Error GoTo delerr
s = MsgBox("确定删除这组记录吗?", vbQuestion + vbOKCancel, "确定删除")
If s = 1 Then
BeginTrans
Data1.Recordset.Delete
CommitTrans
Data1.Recordset.MoveNext
Data1.Refresh
If Data1.Recordset.RecordCount > 0 Then
If Data1.Recordset.EOF Then
Data1.Recordset.MoveNext
End If
End If
End If
Exit Sub
delerr:
MsgBox Err.Description
End Sub

Private Sub Command5_Click()
Dim position As Variant
Dim s As String
On Error GoTo updateerr
BeginTrans
Data1.Recordset.Update
CommitTrans
Data1.Refresh
initial_button
Exit Sub
updateerr:
MsgBox Err.Description
End Sub

Private Sub Command6_Click()
On Error GoTo cancelerr
Data1.Recordset.CancelUpdate
initial_button
Exit Sub
cancelerr:
 MsgBox Err.Description
End Sub

Public Sub initial_button()
If Data1.Recordset.RecordCount = 0 Then
Command1.Enabled = True
Command4.Enabled = False
Command5.Enabled = False
Command6.Enabled = False
Else
Command1.Enabled = True
Command4.Enabled = True
Command5.Enabled = False
Command6.Enabled = False
End If
End Sub



Private Sub Command7_Click()
Pic.Enabled = True

End Sub

Private Sub Form_Activate()
initial_button
End Sub

Public Sub savecancel()
Command1.Enabled = False
Command4.Enabled = False
Command5.Enabled = True
Command6.Enabled = True
End Sub




--------------------编程问答-------------------- 数据查询后赋值给数组变量,对PICTUREBOX绘图:
Dim gyhDate As String
Dim chaxun11 As String
Dim chaxun2 As String
Dim zsl As Integer
Dim quexian(9, 6000) As Variant
Dim i As Integer
Dim j As Integer
Dim X As Integer
Dim Y As Integer
Dim fnt As Integer
Dim txt As Variant
Dim dd As Variant
Dim wp As Variant
Public Function xp(colvb As Variant, xx As Variant, yy As Variant, txt As Variant)
Picture1.ForeColor = colvb 'QBColor(14)
Picture1.CurrentX = xx
Picture1.CurrentY = yy
Picture1.Print txt '
End Function
Private Sub Command1_Click()
gyhDate = Adodc3.Recordset(0)
chaxun1 = "select * from jishijilu  where gyh_riqi='" & gyhDate & "' order by shijian"
mdh = chaxun1
Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Ldgz\wd.mdb;Persist Security Info=False"
Adodc1.RecordSource = mdh
Adodc1.Refresh
Adodc1.Recordset.MoveLast
chaxun11 = "select * from jishijilu where gyh_riqi='" & gyhDate & "'"
chaxun2 = " order by gyh_riqi,shijian"
mdh = chaxun11 & chaxun2
Adodc2.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Ldgz\wd.mdb;Persist Security Info=False"
Adodc2.RecordSource = mdh
Adodc2.Refresh
zsl = Adodc2.Recordset.RecordCount
Text2 = zsl
Adodc2.Recordset.MoveFirst
End Sub

Private Sub Command2_Click()
Picture1.Cls
colvb = vbWhite
xx = 100
yy = 150
txt = "℃"
wp = xp(colvb, xx, yy, txt)
yy = 350
txt = "100"
wp = xp(colvb, xx, yy, txt)
xx = 200
yy = 1850
txt = "50"
wp = xp(colvb, xx, yy, txt)
yy = 3350
xx = 300
txt = "0"
wp = xp(colvb, xx, yy, txt)
xx = 100
yy = 4850
txt = "-50"
wp = xp(colvb, xx, yy, txt)
xx = 0
yy = 6350
txt = "-100"
wp = xp(colvb, xx, yy, txt)
xx = 10800 + 100
yy = 150
txt = "℃"
wp = xp(colvb, xx, yy, txt)
yy = 350
txt = "100"
wp = xp(colvb, xx, yy, txt)
xx = 10800 + 200
yy = 1850
txt = "50"
wp = xp(colvb, xx, yy, txt)
yy = 3350
xx = 10800 + 300
txt = "0"
wp = xp(colvb, xx, yy, txt)
xx = 10800 + 100
yy = 4850
txt = "-50"
wp = xp(colvb, xx, yy, txt)
xx = 10800 + 0
yy = 6350
txt = "-100"
wp = xp(colvb, xx, yy, txt)
'真空坐标

colvb = vbRed
xx = 11400
yy = 150
txt = "Pa"
wp = xp(colvb, xx, yy, txt)
yy = 350
txt = "1000"
wp = xp(colvb, xx, yy, txt)
xx = 11500
yy = 1850
txt = "100"
wp = xp(colvb, xx, yy, txt)
yy = 3350
xx = 11600
txt = "10"
wp = xp(colvb, xx, yy, txt)
xx = 11700
yy = 4850
txt = "1"
wp = xp(colvb, xx, yy, txt)
xx = 11500
yy = 6350
txt = "0.1"
wp = xp(colvb, xx, yy, txt)

xx = 500
yy = 150
txt = "Pa"
wp = xp(colvb, xx, yy, txt)
yy = 350
txt = "1000"
wp = xp(colvb, xx, yy, txt)
yy = 150
xx = 2200
txt = "6hr"
wp = xp(colvb, xx, yy, txt)
xx = 4000
txt = "12hr"
wp = xp(colvb, xx, yy, txt)
xx = 5800
txt = "18hr"
wp = xp(colvb, xx, yy, txt)
xx = 7600
txt = "24hr"
wp = xp(colvb, xx, yy, txt)
xx = 9400
txt = "30hr"
wp = xp(colvb, xx, yy, txt)
xx = 13000
txt = "42hr"
wp = xp(colvb, xx, yy, txt)
xx = 14800
txt = "48hr"
wp = xp(colvb, xx, yy, txt)
xx = 16600
txt = "54hr"
wp = xp(colvb, xx, yy, txt)
xx = 18400
txt = "60hr"
wp = xp(colvb, xx, yy, txt)
xx = 20200
txt = "66hr"
wp = xp(colvb, xx, yy, txt)
xx = 22000
txt = "72hr"
wp = xp(colvb, xx, yy, txt)
xx = 23800
txt = "78hr"
wp = xp(colvb, xx, yy, txt)
xx = 25600
txt = "84hr"
wp = xp(colvb, xx, yy, txt)
xx = 600
yy = 1850
txt = "100"
wp = xp(colvb, xx, yy, txt)
yy = 3350
xx = 11600
txt = "10"
wp = xp(colvb, xx, yy, txt)
xx = 700
yy = 4850
txt = "1"
wp = xp(colvb, xx, yy, txt)
xx = 600
yy = 6350
txt = "0.1"
wp = xp(colvb, xx, yy, txt)
xx = 22100
yy = 350
txt = "1000"
wp = xp(colvb, xx, yy, txt)
yy = 1850
txt = " 100"
wp = xp(colvb, xx, yy, txt)
yy = 3350
txt = "  10"
wp = xp(colvb, xx, yy, txt)
yy = 4850
txt = "   1"
wp = xp(colvb, xx, yy, txt)
yy = 6350
txt = "   0.1"
wp = xp(colvb, xx, yy, txt) --------------------编程问答-------------------- 接上贴:
'画格

Picture1.ForeColor = vbWhite
Picture1.Line (450, 700)-(500, 700)
Picture1.Line (450, 1000)-(500, 1000)
Picture1.Line (450, 1300)-(500, 1300)
Picture1.Line (450, 1600)-(500, 1600)
Picture1.ForeColor = vbRed

Picture1.Line (500, 566.7)-(550, 566.7)
Picture1.Line (500, 733.3)-(550, 733.3)
Picture1.Line (500, 900)-(550, 900)
Picture1.Line (500, 1066.7)-(550, 1066.7)
Picture1.Line (500, 1233.3)-(550, 1233.3)
Picture1.Line (500, 1400)-(550, 1400)
Picture1.Line (500, 1566.7)-(550, 1566.7)
Picture1.Line (500, 1733.3)-(550, 1733.3)
Picture1.Line (500, 2066.7)-(550, 2066.7)
Picture1.Line (500, 2233.3)-(550, 2233.3)
Picture1.Line (500, 2400)-(550, 2400)
Picture1.Line (500, 2566.7)-(550, 2566.7)
Picture1.Line (500, 2733.3)-(550, 2733.3)
Picture1.Line (500, 2900)-(550, 2900)
Picture1.Line (500, 3066.7)-(550, 3066.7)
Picture1.Line (500, 3233.3)-(550, 3233.3)
Picture1.Line (500, 3566.7)-(550, 3566.7)
Picture1.Line (500, 3733.3)-(550, 3733.3)
Picture1.Line (500, 3900)-(550, 3900)
Picture1.Line (500, 4066.7)-(550, 4066.7)
Picture1.Line (500, 4233.3)-(550, 4233.3)
Picture1.Line (500, 4400)-(550, 4400)
Picture1.Line (500, 4566.7)-(550, 4566.7)
Picture1.Line (500, 4733.3)-(550, 4733.3)
Picture1.Line (500, 5066.7)-(550, 5066.7)
Picture1.Line (500, 5233.3)-(550, 5233.3)
Picture1.Line (500, 5400)-(550, 5400)
Picture1.Line (500, 5566.7)-(550, 5566.7)
Picture1.Line (500, 5733.3)-(550, 5733.3)
Picture1.Line (500, 5900)-(550, 5900)
Picture1.Line (500, 6066.7)-(550, 6066.7)
Picture1.Line (500, 6233.3)-(550, 6233.3)
Picture1.ForeColor = vbWhite
Picture1.Line (450, 400)-(25700, 400)
Picture1.Line (450, 1900)-(25700, 1900)
Picture1.Line (450, 3400)-(25700, 3400)
Picture1.Line (450, 4900)-(25700, 4900)
Picture1.Line (450, 6400)-(25700, 6400)
Picture1.Line (450, 2200)-(500, 2200)
Picture1.Line (450, 2500)-(500, 2500)
Picture1.Line (450, 2800)-(500, 2800)
Picture1.Line (450, 3100)-(500, 3100)
Picture1.Line (450, 3700)-(500, 3700)
Picture1.Line (450, 4000)-(500, 4000)
Picture1.Line (450, 4300)-(500, 4300)
Picture1.Line (450, 4600)-(500, 4600)
Picture1.Line (450, 5200)-(500, 5200)
Picture1.Line (450, 5500)-(500, 5500)
Picture1.Line (450, 5800)-(500, 5800)
Picture1.Line (450, 6100)-(500, 6100)
Picture1.Line (500, 400)-(500, 6400)
Picture1.Line (500 + 0, 400)-(500 + 0, 6400)
Picture1.Line (1400 + 0, 400)-(1400 + 0, 6400)
Picture1.Line (2300 + 0, 400)-(2300 + 0, 6400)
Picture1.Line (3200 + 0, 400)-(3200 + 0, 6400)
Picture1.Line (4100 + 0, 400)-(4100 + 0, 6400)
Picture1.Line (5000 + 0, 400)-(5000 + 0, 6400)
Picture1.Line (5900 + 0, 400)-(5900 + 0, 6400)
Picture1.Line (6800 + 0, 400)-(6800 + 0, 6400)
Picture1.Line (7700 + 0, 400)-(7700 + 0, 6400)
Picture1.Line (8600 + 0, 400)-(8600 + 0, 6400)
Picture1.Line (9500 + 0, 400)-(9500 + 0, 6400)
Picture1.Line (10400 + 0, 400)-(10400 + 0, 6400)
Picture1.Line (11300, 400)-(11300, 6400)
Picture1.Line (12200, 400)-(12200, 6400)
Picture1.Line (13100, 400)-(13100, 6400)
Picture1.Line (14000, 400)-(14000, 6400)
Picture1.Line (14900, 400)-(14900, 6400)
Picture1.Line (15800, 400)-(15800, 6400)
Picture1.Line (16700, 400)-(16700, 6400)
Picture1.Line (17600, 400)-(17600, 6400)
Picture1.Line (18500, 400)-(18500, 6400)
Picture1.Line (19400, 400)-(19400, 6400)
Picture1.Line (20300, 400)-(20300, 6400)
Picture1.Line (21200, 400)-(21200, 6400)
Picture1.Line (22100, 400)-(22100, 6400)
Picture1.Line (23000, 400)-(23000, 6400)
Picture1.Line (23900, 400)-(23900, 6400)
Picture1.Line (24800, 400)-(24800, 6400)
Picture1.Line (25700, 400)-(25700, 6400)
For i = 0 To zsl - 1
    quexian(0, i) = Adodc2.Recordset(0)
    For j = 2 To 9
        quexian(j, i) = Adodc2.Recordset(j)
    Next j
    Adodc2.Recordset.MoveNext
Next i
For j = 0 To zsl - 1
Picture1.Line (j * 5 + 500, quexian(2, j) * -30 + 3399)-(j * 5 + 500, quexian(2, j) * -30 + 3401), vbRed, BF
Picture1.Line (j * 5 + 500, quexian(3, j) * -30 + 3399)-(j * 5 + 500, quexian(3, j) * -30 + 3401), QBColor(7), BF
Picture1.Line (j * 5 + 500, quexian(4, j) * -30 + 3399)-(j * 5 + 500, quexian(4, j) * -30 + 3401), vbBlack, BF
Picture1.Line (j * 5 + 500, quexian(5, j) * -30 + 3399)-(j * 5 + 500, quexian(5, j) * -30 + 3401), vbYellow, BF
Picture1.Line (j * 5 + 500, quexian(6, j) * -30 + 3399)-(j * 5 + 500, quexian(6, j) * -30 + 3401), vbGreen, BF
Next
End Sub
--------------------编程问答-------------------- 有个非常好用的VB曲线控件Apisoft Data Analysis ,功能非常强大。
支持滚屏动态画取线、历史曲线回放,动态分析,鼠标取点值等实用功能。
下载地址:www.apisoft.cn/vbline.htm
QQ:905906 --------------------编程问答-------------------- 有个非常好用的VB曲线控件Apisoft Data Analysis ,功能非常强大。
支持滚屏动态画取线、历史曲线回放,动态分析,曲线放大缩小、鼠标取点值等实用功能。
下载地址:www.apisoft.cn/vbline.htm
QQ:905906 13255535552 --------------------编程问答-------------------- 以后需再关注,现在先帮你顶一下
补充:VB ,  数据库(包含打印,安装,报表)
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,