📄 digitbox.ctl
字号:
End If
'Wrong format
If Len(sDispStr) <> 8 Then
sDispStr = String$(2, Chr$(1)) & ":" & String$(2, Chr$(1)) & ":" & String$(2, Chr$(1))
Else
'Make sure the colons are in the right place
If (Mid$(sDispStr, 3, 1) <> ":") And (Mid$(sDispStr, 5, 1) <> ":") Then
sDispStr = String$(2, Chr$(1)) & ":" & String$(2, Chr$(1)) & ":" & String$(2, Chr$(1))
End If
End If
End If
Else
'If we get here it is either General or Decimal format
If m_DigitError Then
Select Case m_DigitFormat
Case dgGeneral
sDispStr = "Err"
Case dgDecimal
sDispStr = "Err."
End Select
End If
If m_DigitFormat = dgDecimal Then 'decimal
' We are going to be padding the string with Chr$(1) if it is too short
' We will adjust everything by one to account for the decimal point
iAdjust = 1
'If there is no decimal ponit then add it
If InStr(sDispStr, ".") = 0 Then
sDispStr = sDispStr & ".0"
End If
End If
'Lop off chars if it is too long
'or add Chr$(1)s to pad the string if its too short.
If m_DigitJustify = dgRight Then 'Right justifeid
If (Len(sDispStr) - iAdjust) < m_DigitPlaceHolders Then
sDispStr = String$(m_DigitPlaceHolders - (Len(sDispStr) - iAdjust), Chr$(1)) & sDispStr
ElseIf ((Len(sDispStr) - iAdjust)) > m_DigitPlaceHolders Then
sDispStr = Right$(sDispStr, m_DigitPlaceHolders + iAdjust)
End If
Else 'Left justifeid
If (Len(sDispStr) - iAdjust) < m_DigitPlaceHolders Then
sDispStr = sDispStr & String$(m_DigitPlaceHolders - ((Len(sDispStr) - iAdjust)), Chr$(1))
ElseIf ((Len(sDispStr) - iAdjust)) > m_DigitPlaceHolders Then
sDispStr = Right$(sDispStr, m_DigitPlaceHolders + iAdjust)
End If
End If
End If
FixDisplay = sDispStr
End Function
Private Sub RedrawControl()
Dim lSrcX As Long
Dim lSrcY As Long
Dim lDestX As Long
Dim sValueStr As String
Dim i As Integer
Dim iThisDigit As Integer
Dim lRet As Long
Dim iDigitHeight As Integer
Dim iDigitWidth As Integer
Dim iOLOffSet As Integer
Dim iSpotWidth As Integer
Dim rc As Rect
UserControl.Cls
'If DigitOutLine = True then Draw the outline
If m_DigitOutLine Then
'We will need to push everything right and down 1 pixel to account for the outline
iOLOffSet = 1
rc.Left = 0
rc.Top = 0
rc.Right = UserControl.ScaleWidth
rc.Bottom = UserControl.ScaleHeight
lRet = DrawEdge(UserControl.hdc, rc, EDGE_SUNKEN, BF_BOTTOMRIGHT)
lRet = DrawEdge(UserControl.hdc, rc, EDGE_SUNKEN, BF_TOPLEFT)
End If
'FixDisplay() makes sure the DigitDisplay property is formatted correctly
sValueStr = FixDisplay()
'Get the Width and Height of the digit
'Set the Source Y for the proper color
'Based on whether they are large or small digits
If m_DigitSize = dgSmall Then
lSrcY = m_DigitColor * SMALL_HEIGHT
iDigitHeight = SMALL_HEIGHT
iDigitWidth = SMALL_WIDTH
Else
lSrcY = (m_DigitColor * LARGE_HEIGHT) + (SMALL_HEIGHT * 3)
iDigitHeight = LARGE_HEIGHT
iDigitWidth = LARGE_WIDTH
End If
'Loop through the string and display each char
For i = 1 To Len(sValueStr)
Select Case Mid$(sValueStr, i, 1)
'Chr$(1) is the ghosted placeholder
Case Chr$(1)
iThisDigit = 10
lSrcX = iThisDigit * iDigitWidth
iSpotWidth = iDigitWidth
Case "-" 'minus sign
iThisDigit = 11
lSrcX = iThisDigit * iDigitWidth
iSpotWidth = iDigitWidth
Case "E"
iThisDigit = 12
lSrcX = iThisDigit * iDigitWidth
iSpotWidth = iDigitWidth
Case "r"
iThisDigit = 13
lSrcX = iThisDigit * iDigitWidth
iSpotWidth = iDigitWidth
Case ":" 'Colon for time
iThisDigit = 14
iSpotWidth = COLON_WIDTH
lSrcX = iThisDigit * iDigitWidth
Case "." 'period for decimal
iThisDigit = 14
iSpotWidth = COLON_WIDTH
lSrcX = iThisDigit * iDigitWidth + COLON_WIDTH
Case Else ' Digitds 0 - 9
iThisDigit = Val(Mid$(sValueStr, i, 1))
lSrcX = iThisDigit * iDigitWidth
iSpotWidth = iDigitWidth
End Select
'Bitblt from frmMain.picDigits.hDC to the UserControl.hDC
lRet = BitBlt(UserControl.hdc, lDestX + iOLOffSet, 0 + iOLOffSet, iSpotWidth, iDigitHeight, frmMain.picDigits.hdc, lSrcX, lSrcY, SRCCOPY)
'Move to the next spot in the UserControl
lDestX = lDestX + iSpotWidth
Next
End Sub
Private Sub UserControl_AmbientChanged(PropertyName As String)
RedrawControl
UserControl.Refresh
End Sub
Private Sub UserControl_InitProperties()
m_DigitSize = dgSmall
m_DigitColor = dgRed
m_DigitOutLine = True
m_DigitPlaceHolders = 4
m_DigitDisplay = "543"
m_DigitJustify = dgRight
m_DigitFormat = dgGeneral
m_DigitError = False
RedrawControl
End Sub
Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
m_DigitDisplay = PropBag.ReadProperty("DigitDisplay", "1234")
m_DigitPlaceHolders = PropBag.ReadProperty("DigitPlaceHolders", 4)
m_DigitSize = PropBag.ReadProperty("DigitSize", dgSmall)
m_DigitColor = PropBag.ReadProperty("DigitColor", dgRed)
m_DigitOutLine = PropBag.ReadProperty("DigitOutLine", True)
m_DigitJustify = PropBag.ReadProperty("DigitJustify", dgRight)
m_DigitFormat = PropBag.ReadProperty("DigitFormat", dgGeneral)
m_DigitError = PropBag.ReadProperty("DigitError", False)
UserControl_Resize
End Sub
Private Sub UserControl_Resize()
Dim iAddOL As Integer
Dim iAddWidth As Integer
Dim iPlaceHolders As Integer
iPlaceHolders = m_DigitPlaceHolders
'If the Format is Time or Decimal then set the Placehoders and adhust width for colon or period
If m_DigitFormat = dgShortTime Then
iPlaceHolders = 4
iAddWidth = COLON_WIDTH
ElseIf m_DigitFormat = dgLongTime Then
iPlaceHolders = 6
iAddWidth = (COLON_WIDTH * 2)
ElseIf m_DigitFormat = dgDecimal Then
iAddWidth = COLON_WIDTH
End If
'If OutLine = true then add 2 to the Height and Width to account for it
If m_DigitOutLine Then iAddOL = 2
'Set the controls hiieght and width based on whether they are large or small digits
If m_DigitSize = dgSmall Then
UserControl.Height = (SMALL_HEIGHT + iAddOL) * Screen.TwipsPerPixelY
UserControl.Width = ((SMALL_WIDTH * iPlaceHolders) + iAddOL + iAddWidth) * Screen.TwipsPerPixelX
Else
UserControl.Height = (LARGE_HEIGHT + iAddOL) * Screen.TwipsPerPixelY
UserControl.Width = ((LARGE_WIDTH * iPlaceHolders) + iAddOL + iAddWidth) * Screen.TwipsPerPixelX
End If
RedrawControl
End Sub
Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
Call PropBag.WriteProperty("DigitDisplay", m_DigitDisplay, "1234")
Call PropBag.WriteProperty("DigitPlaceHolders", m_DigitPlaceHolders, 4)
Call PropBag.WriteProperty("DigitSize", m_DigitSize, dgSmall)
Call PropBag.WriteProperty("DigitColor", m_DigitColor, dgRed)
Call PropBag.WriteProperty("DigitOutLine", m_DigitOutLine, True)
Call PropBag.WriteProperty("DigitJustify", m_DigitJustify, dgRight)
Call PropBag.WriteProperty("DigitFormat", m_DigitFormat, dgGeneral)
Call PropBag.WriteProperty("DigitError", m_DigitError, False)
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -