⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 morphlcd.ctl

📁 一个简单的电子看板程序,可根据需要设定节拍时间
💻 CTL
📖 第 1 页 / 共 5 页
字号:
Private DigitHeight             As Long                     ' height of a main value digit, in pixels.
Private DigitWidthExp           As Long                     ' width of an exponent digit, in pixels.
Private DigitHeightExp          As Long                     ' height of an exponent digit, in pixels.

Private ChangingPicture As Boolean                          ' so control knows to reblit new bg to virtual DC.
Private PreviousMainValue       As String                   ' used to determine whether to display new digit.
Private PreviousExponentValue   As String                   ' used to determine whether to display new digit.
Private PreviousNegative        As Boolean                  ' flag to determine sign of previously displayed value.

'  default property value constants.
Private Const m_def_BackAngle = 90                          ' horizontal gradient.
Private Const m_def_BackColor1 = &H0                        ' black background gradient start color.
Private Const m_def_BackColor2 = &H0                        ' black background gradient end color.
Private Const m_def_BackMiddleOut = True                    ' middle-out gradient display.
Private Const m_def_BorderWidth = 1                         ' 1-pixel wide border.
Private Const m_def_BorderColor = &HFF0000                  ' blue border color.
Private Const m_def_BurnInColor = &H505000                  ' dark cyan simulated segment burn-in color.
Private Const m_def_BurnInColorNeg = &H505000               ' dark cyan negative value burn-in color.
Private Const m_def_CurveBottomLeft = 0                     ' no curvature.
Private Const m_def_CurveBottomRight = 0                    ' no curvature.
Private Const m_def_CurveTopLeft = 0                        ' no curvature.
Private Const m_def_CurveTopRight = 0                       ' no curvature.
Private Const m_def_DecimalSeparator = 1                    ' period decimal separator.
Private Const m_def_InterDigitGap = 6                       ' 6 pixels between main LCD digits.
Private Const m_def_InterDigitGapExp = 2                    ' 2 pixels between exponent digits.
Private Const m_def_InterSegmentGap = 0                     ' no segment gap in main LCD digit segments.
Private Const m_def_InterSegmentGapExp = 0                  ' no segment gap in exponent digits.
Private Const m_def_NumDigits = 20                          ' 20 main value digits.
Private Const m_def_NumDigitsExp = 4                        ' 3 digits + minus sign.
Private Const m_def_PictureMode = 0                         ' normal picture display.
Private Const m_def_SegmentFillStyle = 1                    ' solid filled digits
Private Const m_def_SegmentHeight = 8                       ' main segments 8 pixels high.
Private Const m_def_SegmentHeightExp = 6                    ' exponent digit segments 4 pixels high.
Private Const m_def_SegmentLitColor = &HFFFF00              ' cyan lit positive value segment.
Private Const m_def_SegmentLitColorNeg = &HFFFF00           ' cyan lit negative value segment.
Private Const m_def_SegmentStyle = 2                        ' rectangular main digit segments.
Private Const m_def_SegmentStyleExp = 2                     ' rectangular exponent digit segments.
Private Const m_def_SegmentWidth = 3                        ' main segments 3 pixels high.
Private Const m_def_SegmentWidthExp = 3                     ' exponent segments 3 pixels wide.
Private Const m_def_ShowBurnIn = True                       ' show 'burned-in' segments.
Private Const m_def_ShowExponent = True                     ' show exponent.
Private Const m_def_ShowThousandsSeparator = False          ' don't show thousands separator.
Private Const m_def_Theme = 5                               ' 'rectangular medium' theme selected.
Private Const m_def_ThousandsGrouping = 3                   ' thousands separator every three digits.
Private Const m_def_ThousandsSeparator = 0                  ' comma thousands separator.
Private Const m_def_Value = "1234567890"                    ' displayed at first by default in design mode.
Private Const m_def_XOffset = 5                             ' 5 pixels from control left border.
Private Const m_def_XOffsetExp = 355                        ' 355 pixels from control left border.
Private Const m_def_YOffset = 5                             ' display main digits 5 pixels down from top edge.
Private Const m_def_YOffsetExp = 5                          ' display exponent 5 pixels from control top.

'  property variables.
Private m_BackAngle              As Single                  ' angle of background gradient.
Private m_BackColor1             As OLE_COLOR               ' first color of background gradient.
Private m_BackColor2             As OLE_COLOR               ' second color of background gradient.
Private m_BackMiddleOut          As Boolean                 ' if True, gradient displays in middle-out fashion.
Private m_BorderColor            As OLE_COLOR               ' border color.
Private m_BorderWidth            As Integer                 ' width, in pixels, of control border.
Private m_BurnInColor            As OLE_COLOR               ' color of simulated LCD digit 'burn-in'.
Private m_BurnInColorNeg         As OLE_COLOR               ' burn in color when value is negative.
Private m_CurveBottomLeft        As Long                    ' amount of curve for bottom left corner.
Private m_CurveBottomRight       As Long                    ' amount of curve for bottom right corner.
Private m_CurveTopLeft           As Long                    ' amount of curve for top left corner.
Private m_CurveTopRight          As Long                    ' amount of curve for top right corner.
Private m_DecimalSeparator       As SeparatorOptions        ' decimal separator character ("." in U.S.).
Private m_InterDigitGap          As Long                    ' # of pixels separating each main value digit.
Private m_InterDigitGapExp       As Long                    ' # of pixels separating each exponent digit.
Private m_InterSegmentGap        As Long                    ' # of pixels separating main value LCD segments.
Private m_InterSegmentGapExp     As Long                    ' # of pixels separating exponent LCD segments.
Private m_NumDigits              As Long                    ' number of digits to display.
Private m_NumDigitsExp           As Long                    ' number of exponent digits to display.
Private m_Picture                As Picture                 ' bitmap to be displayed in lieu of gradient.
Private m_PictureMode            As LCDPicModeOptions       ' normal, stretched or tiled bitmap display options.
Private m_SegmentFillStyle       As SegmentFillStyleOptions ' solid or filament-style segment styles.
Private m_SegmentHeight          As Long                    ' # of pixels in long dimension of main value segment.
Private m_SegmentHeightExp       As Long                    ' # of pixels in short dimension of exponent segment.
Private m_SegmentLitColor        As OLE_COLOR               ' the color of displayed (non burn-in) segments.
Private m_SegmentLitColorNeg     As OLE_COLOR               ' lit segment color when value is negative.
Private m_SegmentStyle           As SegmentStyleOptions     ' hexagonal, trapezoidal, or rectangular segments.
Private m_SegmentStyleExp        As SegmentStyleOptions     ' hexagonal, trapezoidal, or rectangular segments.
Private m_SegmentWidth           As Long                    ' # of pixels in short dimension of main value segment.
Private m_SegmentWidthExp        As Long                    ' # of pixels in short dimension of exponent segment.
Private m_ShowBurnIn             As Boolean                 ' if True, simulated digit 'burn-in' is displayed.
Private m_ShowExponent           As Boolean                 ' if True, exponent portion of value is shown.
Private m_ShowThousandsSeparator As Boolean                 ' display thousands separator? boolean.
Private m_Theme                  As LCDThemeOptions         ' user-definable and selectable display theme.
Private m_ThousandsGrouping      As Long                    ' how many digits between thousands separators.
Private m_ThousandsSeparator     As SeparatorOptions        ' thousands separator character ("," in U.S.).
Private m_Value                  As String                  ' the value to be displayed.
Private m_XOffset                As Long                    ' # of pixels from left to display main value.
Private m_XOffsetExp             As Long                    ' # of pixels from left to display exponent.
Private m_YOffset                As Long                    ' # of pixels from top to display main value.
Private m_YOffsetExp             As Long                    ' # of pixels from top to display exponent.

' declares for virtual background bitmap.
Private VirtualBackgroundDC     As Long                     ' handle of the created DC.
Private mMemoryBitmap           As Long                     ' Handle of the created bitmap.
Private mOrginalBitmap          As Long                     ' used in destroying virtual DC.

'<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
'<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Events >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
'<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

Private Sub UserControl_Initialize()

'*************************************************************************
'* initializes variables at the start of the control's existence.        *
'*************************************************************************

'  initialize the display patterns for the LCD segments.  Segment
'  positions on the 7-segment LCD start with #1 on top, go clockwise.
'  The center segment is #7.  A "1" means the segment is lit.
   DisplayPattern(0) = "1111110"    ' zero.
   DisplayPattern(1) = "0110000"    ' one.
   DisplayPattern(2) = "1101101"    ' two.
   DisplayPattern(3) = "1111001"    ' three.
   DisplayPattern(4) = "0110011"    ' four.
   DisplayPattern(5) = "1011011"    ' five.
   DisplayPattern(6) = "1011111"    ' six.
   DisplayPattern(7) = "1110000"    ' seven.
   DisplayPattern(8) = "1111111"    ' eight.
   DisplayPattern(9) = "1111011"    ' nine.
   DisplayPattern(10) = "0000000"   ' for display of 'burn-in' unused digits.
   DisplayPattern(11) = "0000001"   ' minus sign.
   DisplayPattern(12) = "1110111"   ' Hex "A".
   DisplayPattern(13) = "0011111"   ' Hex "b". (have to do it lowercase so as not to confuse it with "8".)
   DisplayPattern(14) = "1001110"   ' Hex "C".
   DisplayPattern(15) = "0111101"   ' Hex "d". (have to do it lowercase so as not to confuse it with "0".)
   DisplayPattern(16) = "1001111"   ' Hex "E".
   DisplayPattern(17) = "1000111"   ' Hex "F".

'  initialize the decimal separator location to 'no decimal separator'.
   DecimalSeparatorPos.x = -1

'  initialize the colon location to 'no colon'.
   ColonPos.TopPoint.x = -1

End Sub

Private Sub UserControl_Resize()

'*************************************************************************
'* just used in design mode at the moment.                               *
'*************************************************************************

   CalculateBackGroundGradient
   RedrawControl

End Sub

Private Sub UserControl_Show()

'*************************************************************************
'* dimension the thousands flag to match size of .NumDigits property.    *
'*************************************************************************

   ReDim ThousandsFlag(0 To m_NumDigits - 1)

'  for showing the control when placed on form in design mode.
   If Not Ambient.UserMode Then
      InitLCDDisplayCharacteristics
      RedrawControl
   End If

End Sub

Private Sub UserControl_Terminate()

'*************************************************************************
'* destroys all active objects and regions prior to control termination. *
'*************************************************************************

   Dim i As Long    ' loop variable.

'  delete digit segment region objects.
   For i = 0 To 9
      DeleteObject LCDSegment(i)
      DeleteObject LCDSegmentExp(i)
   Next i

'  delete digit segment color brushes.
   DeleteObject LCDLitColorBrush
   DeleteObject LCDBurnInColorBrush
   DeleteObject LCDLitColorBrushNeg
   DeleteObject LCDBurnInColorBrushNeg

'  destroy the virtual DC's used in background storage.
   DestroyVirtualDC
   DestroyPattern

End Sub

'<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
'<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Graphics >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
'<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

Private Sub DisplayValue(sValue As String, ByVal ForceDisplay As Boolean)

'*************************************************************************
'* displays the value stored in the .Value property.  The 'ForceDisplay' *
'* parameter is used to force a redisplay when a property is changed.    *
'*************************************************************************

   Dim sMainValue     As String    ' non-exponential, main value.
   Dim sExponentValue As String    ' up to n_NumDigitsExp long exponent (including sign).
   Dim IsBase10       As Boolean   ' not using this function return value now.

'  just in case, so exponent "E" and hex digits get processed correctly.
   sValue = UCase(sValue)

'  a catch for if there isn't a 0 in front of the decimal separator in a
'  fractional value.  (That won't happen if control is used correctly.)
   If Left(sValue, 1) = "." Then
      sValue = "0" & sValue
   End If

'  determine the color brush to use when displaying the value.
   If Val(sValue) < 0 Then

'     value is negative; use negative value color brushes.
      CurrentLitColorBrush = LCDLitColorBrushNeg
      CurrentBurnInColorBrush = LCDBurnInColorBrushNeg

'     a word about the PreviousNegative stuff... Normally individual display digits are drawn
'     only if the digit has changed from the previous displayed digit in the same position.
'     This saves a great deal of time in my timing tests.  However, when the sign is changed
'     when a new value is displayed, we have to force a redraw of every digit, even if they're
'     the same as in previous display.  That way a displayed value can't be a mishmash of
'     positive and negative value colors.
      If Not PreviousNegative Then
         PreviousMainValue = String(m_NumDigits, "X")
         PreviousExponentValue = String(m_NumDigitsExp, "X")
      End If
      PreviousNegative = True

   Else

'     value is positive; use regular (positive number) color brushes.
      CurrentLitColorBrush = LCDLitColorBrush
      CurrentBurnInColorBrush = LCDBurnInColorBrush

      If PreviousNegative Then
         PreviousMainValue = String(m_NumDigits, "X")
         PreviousExponentValue = String(m_NumDigitsExp, "X")
      End If
      PreviousNegative = False

   End If

'  separate possible exponent from overall value.
   IsBase10 = SeparateMainValueAndExponent(sValue, sMainValue, sExponentValue)

'  display the main value, and also the exponent if permitted by the ShowExponent property.
   DisplayMainValue sMainValue, ForceDisplay
   If m_ShowExponent Then
      DisplayExponentValue sExponentValue, ForceDisplay
   End If

End Sub

Private Function SeparateMainValueAndExponent(ByVal sValue As String, ByRef sMainValue As String, ByRef ExponentValue As String) As Boolean

'*************************************************************************
'* if it's an exponential base-10 number, separates the exponent and the *
'* main value.  Otherwise returns the value and spaces for exponent.     *
'*************************************************************************

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -