Public Sub OliTagDraw(ByRef pPictureBox As PictureBox, ByVal pOliTag As Double, ByVal pOliTagMax As Double, ByVal pTMP As Double, Optional ByVal pTMP_Max As Double = 100, Optional ByVal pTMP_Min As Double = -40)
'参数:pPictureBox 需要显示油量指示的图片框。pPictureBox的大小不限制,因为本函数自动适应图片框的尺寸。
' pOliTag 油的位置(也可以是重量),必须在0到pOliTagMax之间。
' pOliTagMax 最高油位(就是油装满油桶的位置,也可以是最大重量)默认为100
' pTMP 油的温度,根据温度决定显示油的颜色。必须在pTMP_Min和pTMP_Max之间。
' pTMP_Max 油温度的最高极限。
' pTMP_Min 油温度的最低极限。
Dim tDesHeight As Double
Dim tTMP_Bound As Double
Dim tTMP_Value As Double
Dim tColorLevel As Long
Dim tColor As Long
VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 4665
ClientLeft = 60
ClientTop = 345
ClientWidth = 4680
LinkTopic = "Form1"
ScaleHeight = 4665
ScaleWidth = 4680
StartUpPosition = 3 '窗口缺省
Begin 工程1.ctlOliCask ctlOliCask1
Height = 2055
Left = 120
TabIndex = 3
Top = 240
Width = 615
_extentx = 873
_extenty = 3413
End
Begin VB.HScrollBar HScroll2
Height = 255
Left = 120
Max = 200
Min = -100
TabIndex = 2
Top = 3000
Width = 4455
End
Begin VB.HScrollBar HScroll1
Height = 255
Left = 120
Max = 200
Min = -20
TabIndex = 1
Top = 2640
Width = 4455
End
Begin VB.CommandButton Command1
Caption = "Command1"
Height = 375
Left = 3240
TabIndex = 0
Top = 3840
Width = 1335
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub HScroll1_Change()
Dim tOli As Double
Dim tTMP As Double
tOli = HScroll1.Value
tTMP = HScroll2.Value
ctlOliCask1.Value = tOli
ctlOliCask1.Temperature = tTMP
End Sub
Private Sub HScroll2_Change()
Dim tOli As Double
Dim tTMP As Double
tOli = HScroll1.Value
tTMP = HScroll2.Value
ctlOliCask1.Value = tOli
ctlOliCask1.Temperature = tTMP
If tValueHigh Then
tOliValue = priOliValue_Max
RaiseEvent ValueOver
ElseIf tOliValue < 0 Then
tOliValue = 0
End If
If tFlow Then RaiseEvent ValueFlow
If tTemperatureHigh Then
tTemperature = priTemperature_Max
RaiseEvent TemperatureOver
ElseIf tTemperatureLow Then
tTemperature = priTemperature_Min
RaiseEvent TemperatureLow
End If
Private Sub OliTagDraw(ByRef pPictureBox As PictureBox, ByVal pOliTag As Double, ByVal pOliTagMax As Double, ByVal pTMP As Double, Optional ByVal pTMP_Max As Double = 100, Optional ByVal pTMP_Min As Double = -40, Optional ByVal pBackColor As Long = &H808080)
Dim tDesHeight As Double
Dim tTMP_Bound As Double
Dim tTMP_Value As Double
Dim tColorLevel As Long
Dim tColor As Long
Public Sub OliTagDraw(ByRef pPictureBox As PictureBox, ByVal pOliTag As Double, ByVal pOliTagMax As Double, ByVal pTMP As Double, Optional ByVal pTMP_Max As Double = 100, Optional ByVal pTMP_Min As Double = -40)
Dim tDesHeight As Double
Dim tTMP_Bound As Double
Dim tTMP_Value As Double
Dim tColorLevel As Long
Dim tColor As Long
If tTMP_Value >= 0 And tTMP_Value <= tTMP_Bound Then
tColorLevel = (255 - ((tTMP_Value * 255) / tTMP_Bound))
tColor = tColorLevel * &H100 + &HFF
Else
tColor = &HFFFFFF
End If
With pPictureBox
tDesHeight = .Height - ((pOliTag * .Height) / pOliTagMax)
pPictureBox.Line (0, tDesHeight)-(.Width, .Height), tColor, BF
pPictureBox.Line (0, 0)-(.Width, tDesHeight), &H808080, BF
End With
End Sub
测试代码如下:
Private Sub HScroll1_Change()
Dim tOli As Double
Dim tTMP As Double
tOli = HScroll1.Value
tTMP = HScroll2.Value
OliTagDraw Picture1, tOli, 100, tTMP
End Sub
Private Sub HScroll2_Change()
Dim tOli As Double
Dim tTMP As Double
tOli = HScroll1.Value
tTMP = HScroll2.Value
OliTagDraw Picture1, tOli, 100, tTMP
End Sub
下面是没有写完的内容,实在来不及完成了。
Public Type tpOliCask '油桶类型
ctRadius As Double '内径(mm)
ctHeight As Double '内沿高度(mm)(极限液位)
ctNormTag As Double '规范液位(mm)(警戒液位)
ctPatchTag As Double '补充液位(mm)(解决实际应用中液位探测器可能接触不到桶底问题)
olVolume As Double '容量
olSpecificGravity As Double '比重
tmpValue As Double '温度值(℃)
tmpValueMax As Double '值上限(℃)
tmpValueMin As Double '值下限(℃)
tmpValueWatchful As Double '警戒值(℃)
End Type
Const conPI As Double = 3.14159265358979
Public Function OliCask_TagGetByVolume(ByVal pRadius As Double, ByVal pVolume As Double) As Double
Dim tOutTag As Double
Public Function OliCask_VolumeGetByWeight(ByVal pWeight As Double, Optional ByVal pSpecificGravity As Double = 1, Optional ByVal pCaskWeight As Double = 0) As Double
Dim tOutVolume As Double
OliCask_VolumeGetByWeight = tOutVolume
End Function
Public Function OliCask_WeightGetByVolume(ByVal pVolume As Double, Optional ByVal pSpecificGravity As Double = 1, Optional ByVal pCaskWeight As Double = 0) As Double
Dim tOutWeight As Double
'add picturebox1,picturebox2,vscroll1 to form1,then slide vscroll1:
Option Explicit
Private Sub Form_Load()
Me.Move Screen.Width / 2 - 2000, Screen.Height / 2 - 3000, 4000, 6000
Picture1.Move 200, 200, 3200, 5000
VScroll1.Move 3500, 200, 400, 5000
VScroll1.Min = 100
VScroll1.Max = 0
VScroll1.Value = 5
Picture1.Scale (0, 100)-(100, 0)
Set Picture2.Container = Picture1
Picture2.BackColor = vbYellow
Picture2.BorderStyle = 0
Picture2.Move 0, 5, 100, 5
Picture2.Cls
Picture2.CurrentX = Picture2.Width / 2
Picture2.CurrentY = 0
Picture2.Print " There are 5 L oil in the 100 L tank "
End Sub
Private Sub VScroll1_Change()
Dim h As Integer
h = VScroll1.Value
Picture2.Move 0, h, 100, h
Picture2.Cls
Picture2.CurrentX = 0
Picture2.CurrentY = 0
Picture2.Print " There are " & h & "L oil in the 100L tank "
End Sub