📄 digitbox.ctl
字号:
VERSION 5.00
Begin VB.UserControl DigitBox
AutoRedraw = -1 'True
ClientHeight = 1710
ClientLeft = 0
ClientTop = 0
ClientWidth = 3120
ScaleHeight = 114
ScaleMode = 3 'Pixel
ScaleWidth = 208
ToolboxBitmap = "digitbox.ctx":0000
End
Attribute VB_Name = "DigitBox"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
Option Explicit
Public Enum JustifyConstants
dgLeft = 0
dgRight = 1
End Enum
Public Enum FormatConstants
dgGeneral = 0
dgShortTime = 1
dgLongTime = 2
dgDecimal = 3
End Enum
Public Enum SizeConstants
dgSmall = 0
dgLarge = 1
End Enum
Public Enum ColorConstants
dgBlue = 0
dgGreen = 1
dgRed = 2
End Enum
Const COLON_WIDTH = 5
Const SMALL_WIDTH = 13
Const SMALL_HEIGHT = 21
Const LARGE_WIDTH = 18
Const LARGE_HEIGHT = 27
Private m_DigitSize As WSDigitbox.SizeConstants
Private m_DigitColor As WSDigitbox.ColorConstants
Private m_DigitPlaceHolders As Integer
Private m_DigitDisplay As String
Private m_DigitOutLine As Boolean
Private m_DigitJustify As WSDigitbox.JustifyConstants
Private m_DigitFormat As WSDigitbox.FormatConstants
Private m_DigitError As Boolean
Public Property Get DigitFormat() As WSDigitbox.FormatConstants
DigitFormat = m_DigitFormat
End Property
Public Property Get DigitError() As Boolean
DigitError = m_DigitError
End Property
Public Property Get DigitColor() As WSDigitbox.ColorConstants
DigitColor = m_DigitColor
End Property
Public Property Let DigitColor(ByVal New_Value As WSDigitbox.ColorConstants)
If (New_Value < 0) Or (New_Value > 2) Then New_Value = 1
m_DigitColor = New_Value
PropertyChanged "DigitColor"
UserControl_Resize
End Property
Public Property Let DigitFormat(ByVal New_Value As WSDigitbox.FormatConstants)
If (New_Value < 0) Or (New_Value > 3) Then New_Value = 0
m_DigitFormat = New_Value
PropertyChanged "DigitFormat"
UserControl_Resize
End Property
Public Property Let DigitJustify(ByVal New_Value As WSDigitbox.JustifyConstants)
If (New_Value < 0) Or (New_Value > 1) Then New_Value = 1
m_DigitJustify = New_Value
PropertyChanged "DigitJustify"
RedrawControl
End Property
Public Property Get DigitJustify() As WSDigitbox.JustifyConstants
DigitJustify = m_DigitJustify
End Property
Public Property Get DigitOutLine() As Boolean
DigitOutLine = m_DigitOutLine
End Property
Public Property Let DigitPlaceHolders(ByVal New_Value As Integer)
If (New_Value < 1) Then New_Value = 1
m_DigitPlaceHolders = New_Value
PropertyChanged "DigitPlaceHolders"
UserControl_Resize
End Property
Public Property Let DigitSize(ByVal New_Value As WSDigitbox.SizeConstants)
If (New_Value < 0) Or (New_Value > 1) Then New_Value = 1
m_DigitSize = New_Value
PropertyChanged "DigitSize"
UserControl_Resize
End Property
Public Property Get DigitSize() As WSDigitbox.SizeConstants
DigitSize = m_DigitSize
End Property
Public Property Let DigitOutLine(ByVal New_Value As Boolean)
m_DigitOutLine = New_Value
PropertyChanged "DigitOutLine"
UserControl_Resize
End Property
Public Property Let DigitError(ByVal New_Value As Boolean)
m_DigitError = New_Value
PropertyChanged "DigitError"
RedrawControl
End Property
Public Property Let DigitDisplay(ByVal New_Value As String)
m_DigitDisplay = New_Value
PropertyChanged "DigitDisplay"
RedrawControl
End Property
Public Property Get DigitPlaceHolders() As Integer
DigitPlaceHolders = m_DigitPlaceHolders
End Property
Public Property Get DigitDisplay() As String
DigitDisplay = m_DigitDisplay
End Property
Private Function FixDisplay() As String
Dim sDispStr As String
Dim sTemp As String
Dim i As Integer
Dim iColonCount As Integer
Dim iColonSpot As Integer
Dim iAdjust As Integer
'This function goes through and makes sure the DigitDisplay property is in the proper format.
'I use the Chr$(1) to represent the ghosted place holder. For instance, if the DigitPlaceHolder
'Property is set to 6 but the DigitDisplay property is "234" then I pad it with 3 Chr$(1) to fill it out.
'Get the orignal property value
sTemp = Trim$(m_DigitDisplay)
'Loop through and weed out any non-numeric chars
'Keep colons if Time format, or one period if Decimal format.
For i = 1 To Len(sTemp)
Select Case Mid$(sTemp, i, 1)
Case 0 To 9 ' Allow all digits 0 to 9
sDispStr = sDispStr & Mid$(sTemp, i, 1)
Case ":" ' Allow colons if Format is Time
If (m_DigitFormat = dgShortTime) Or (m_DigitFormat = dgLongTime) Then
iColonCount = iColonCount + 1
If (iColonCount = 1) Then 'one for short time
sDispStr = sDispStr & Mid$(sTemp, i, 1)
End If
If (m_DigitFormat = dgLongTime) And (iColonCount = 2) Then 'two for long time
sDispStr = sDispStr & Mid$(sTemp, i, 1)
End If
End If
Case "." ' Allow one period if Format is Decimal
If (m_DigitFormat = dgDecimal) Then
iColonCount = iColonCount + 1
If (iColonCount = 1) Then
sDispStr = sDispStr & Mid$(sTemp, i, 1)
End If
End If
Case "-" ' Allow one minus sign if Format is General or Decimal
If (m_DigitFormat = dgDecimal) Or (m_DigitFormat = dgGeneral) Then
If (i = 1) Then
sDispStr = sDispStr & Mid$(sTemp, i, 1)
End If
End If
End Select
Next
'If it is time go through and make sure it is a valid time format (e.g. 00:00)
'If not make adjustments
If (m_DigitFormat = dgShortTime) Or (m_DigitFormat = dgLongTime) Then 'Time
If m_DigitError Then
If (m_DigitFormat = dgShortTime) Then
FixDisplay = Chr$(1) & "E:rr"
Else
FixDisplay = String$(2, Chr$(1)) & ":" & Chr$(1) & "E:rr"
End If
Exit Function
End If
If (m_DigitFormat = dgShortTime) Then
'If its 4 then it may be 12 hour format so pad
If Len(sDispStr) = 4 Then
sDispStr = Chr$(1) & sDispStr
End If
'Wrong format
If Len(sDispStr) <> 5 Then
sDispStr = String$(2, Chr$(1)) & ":" & String$(2, Chr$(1))
Else
'Make sure the colon is in the middle
If InStr(sDispStr, ":") <> 3 Then
sDispStr = String$(2, Chr$(1)) & ":" & String$(2, Chr$(1))
End If
End If
Else
'If its 7 then it may be 12 hour format so pad
If Len(sDispStr) = 7 Then
sDispStr = Chr$(1) & sDispStr
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -