picturebox控件实现同时画两条线的问题
1:如果选择Check1在picture上画一条线,如果选择Check2在picture上画另一条线,现在单独选择Check1或Check2都能实现画线,但是如果同时选择Check1和Check2还是画一条线,就是色彩交替而已。请问如何实现同时选择Check1和Check2,画两条不同的线
2:模拟程序全部代码如下:
Dim PrevP(7) As Long
Dim picture1color(7) As Long
Dim j
Dim m
Dim RT1
Dim RT2
Private Sub Check1_Click()
If Check1.Value = 1 Then
RT1 = 1
Timer1.Enabled = True
Timer1.Interval = 200
Else
RT1 = 0
End If
End Sub
Private Sub Check2_Click()
If Check2.Value = 1 Then
RT2 = 1
Timer2.Enabled = True
Timer2.Interval = 200
Else
RT2 = 0
End If
End Sub
Private Sub Form_Load()
For i = 0 To 7
PrevP(i) = 287
Next i
picture1color(0) = &HFF& '设置颜色为红色
picture1color(1) = &H8000& '设置颜色为色深绿色
Timer3.Enabled = True
Timer3.Interval = 200
j = 35
m = 35
End Sub
Private Sub Timer1_Timer()
Dim k
Dim p(0)
Dim result2
If RT1 = 1 Then
'---------------------------------------温度图(T1的实现)的实现开始---------------------------------------------
If IsNumeric(Text1.Text) Then
k = Format(Text1, "##.0 ") * 60 - 50 '+ 1950
If k <= 2050 Then '程序开始的时候波动很大,35度*60-50=2050
k = 2050
End If
Else
Text4.Text = "温度待测 "
End If
result2 = BitBlt(Picture5.hDC, 4, 0, Picture5.Width / Screen.TwipsPerPixelX, Picture5.Height / Screen.TwipsPerPixelY, Picture5.hDC, 0, 0, SRCCOPY)
p(0) = ((-4) * Val(k) / 4095 + 3) * (Picture5.Height / Screen.TwipsPerPixelY)
'p = 4 * ((4095 - CSng(k) - 1023) / 4095 * (Picture5.Height / Screen.TwipsPerPixelY))
' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' '****************************** ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' '
If PrevP(0) <> -1.003 Then
Picture5.Line (4, p(0))-(8, PrevP(0)), picture1color(1) '在picture1上画线并设置颜色
PrevP(0) = p(0)
End If
'---------------------------温度3的数据存入数据库开始-------------------------------------------------------
If wendu1 < Val(k) Then
wendu1 = Val(k)
End If
'---------------------------------------温度图(T1的实现)的实现结束---------------------------------------------
End If
End Sub
Private Sub Timer2_Timer()
Dim k
Dim p(1)
Dim result2
If RT2 = 1 Then
'---------------------------------------温度图(T2的实现)的实现开始---------------------------------------------
If IsNumeric(Text2.Text) Then
k = Format(Text2, "##.0 ") * 60 - 50 '+ 1950
If k <= 2050 Then '程序开始的时候波动很大,35度*60-50=2050
k = 2050
End If
Else
Text5.Text = "温度待测 "
End If
result2 = BitBlt(Picture5.hDC, 4, 0, Picture5.Width / Screen.TwipsPerPixelX, Picture5.Height / Screen.TwipsPerPixelY, Picture5.hDC, 0, 0, SRCCOPY)
p(1) = ((-4) * Val(k) / 4095 + 3) * (Picture5.Height / Screen.TwipsPerPixelY)
'p = 4 * ((4095 - CSng(k) - 1023) / 4095 * (Picture5.Height / Screen.TwipsPerPixelY))
' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' '****************************** ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' '
If PrevP(0) <> -1.003 Then
Picture5.Line (4, p(1))-(8, PrevP(0)), picture1color(2) '在picture1上画线并设置颜色
PrevP(0) = p(1)
End If
'----------------------------温度3的数据存入数据库开始-------------------------------------------------------
If wendu2 < Val(k) Then
wendu2 = Val(k)
End If
'---------------------------------------温度图(T2的实现)的实现结束---------------------------------------------
End If
End Sub
Private Sub Timer3_Timer() '模拟采集卡采集到的温度
If j <= 50 Then
j = j + 0.01
Text1.Text = j
End If
If j = 50 Then
j = 35
End If
If m <= 50 Then
m = m + 0.02
Text2.Text = m
End If
If m = 50 Then
m = 35
End If
End Sub
[解决办法]
Private Sub Timer1_Timer()
'---------------------------------------温度图的实现---------------------------------------------
k(0) = ad_chn(16, ReadLen - 1) '从采集卡中采集数据1
result2 = BitBlt(Picture1.hDC, 4, 0, Picture1.Width / Screen.TwipsPerPixelX, Picture1.Height / Screen.TwipsPerPixelY, Picture1.hDC, 0, 0, SRCCOPY)
p(0) = ((-4) * Val(k(0)) / 4095 + 3) * (Picture1.Height / Screen.TwipsPerPixelY)
k(1) = ad_chn(16, ReadLen - 1) '从采集卡中采集数据2
result2 = BitBlt(Picture1.hDC, 4, 0, Picture1.Width / Screen.TwipsPerPixelX, Picture1.Height / Screen.TwipsPerPixelY, Picture1.hDC, 0, 0, SRCCOPY)
p(1) = ((-4) * Val(k(1)) / 4095 + 3) * (Picture1.Height / Screen.TwipsPerPixelY)
If Check1.Value = vbChecked And Check2.Value = vbUnchecked Then
Call PicLine1
ElseIf Check2.Value = vbChecked And Check1.Value = vbUnchecked Then
Call PicLine2
ElseIf Check1.Value = vbChecked And Check2.Value = vbChecked Then
Call PicLine1
Call PicLine2
End If
PrevP(0) = p(0)
PrevP(1) = p(1)
End Sub
Private Sub Check1_Click()
If Check1.Value = vbChecked Then
Check1.Caption = "画A线 "
ElseIf Check1.Value = vbUnchecked Then
Check1.Caption = "不画A线 "
End If
End Sub
Private Sub Check2_Click()
If Check2.Value = vbChecked Then
Check2.Caption = "画B线 "
ElseIf Check2.Value = vbUnchecked Then
Check2.Caption = "不画B线 "
End If
End Sub
Public Sub PicLine1()
Picture1.Line (4, p(0))-(8, PrevP(0)), picture1color1 '在picture1上画线并设置颜色
End Sub
Public Sub PicLine2()
Picture1.Line (4, p(1))-(8, PrevP(1)), picture1color2 '在picture1上画线并设置颜色
End Sub