DEMO:钟表和电子表(三)

2、电子表

①、设置当前坐标:

Private Type coodinate
    X As Integer
    Y As Integer
End Type

Dim BasePoint As coodinate

②、设置属性过程

'设置背景颜色属性

Property Let BackColor(color As Long)
    p.BackColor = color
End Property

’设置字体颜色属性

Property Let ForeColor(color As Long)
    p.ForeColor = color
End Property

'设置标题,即显示电子表。其中调用了过程来画电子数

Public Property Let Caption(ByVal Value As String)
Dim OrigX As Integer

   OrigX = BasePoint.X
   p.Cls

   While Value <> ""
      If Left$(Value, 1) <> ":" Then
         DrawNumber (Val(Left$(Value, 1)))
         BasePoint.X = BasePoint.X + SegWidth + 3
      Else
         p.Line (BasePoint.X + (SegWidth / 2) - 4, BasePoint.Y + (SegHeight / 2) - 6)-(BasePoint.X + (SegWidth / 2), BasePoint.Y + (SegHeight / 2) - 3), , BF
         p.Line (BasePoint.X + (SegWidth / 2) - 4, BasePoint.Y + (SegHeight / 2) + 4)-(BasePoint.X + (SegWidth / 2), BasePoint.Y + (SegHeight / 2) + 7), , BF
         BasePoint.X = BasePoint.X + SegWidth
      End If
      Value = Right$(Value, Len(Value) - 1)
   Wend

   BasePoint.X = OrigX

End Property

③画1-7线的过程

Public Sub DrawSegment(ByVal SegNum As Integer)
    Select Case SegNum
        Case 1
            p.Line (BasePoint.X + 1, BasePoint.Y)-(BasePoint.X + SegWidth - 1, BasePoint.Y)
            p.Line (BasePoint.X + 2, BasePoint.Y + 1)-(BasePoint.X + SegWidth - 2, BasePoint.Y + 1)
            p.Line (BasePoint.X + 3, BasePoint.Y + 2)-(BasePoint.X + SegWidth - 3, BasePoint.Y + 2)
        Case 2
            p.Line (BasePoint.X + SegWidth - 1, BasePoint.Y + 1)-(BasePoint.X + SegWidth - 1, BasePoint.Y + SegHeight / 2 - 1)
            p.Line (BasePoint.X + SegWidth - 2, BasePoint.Y + 2)-(BasePoint.X + SegWidth - 2, BasePoint.Y + SegHeight / 2)
            p.Line (BasePoint.X + SegWidth - 3, BasePoint.Y + 3)-(BasePoint.X + SegWidth - 3, BasePoint.Y + SegHeight / 2 - 1)

        Case 3
            p.Line (BasePoint.X + SegWidth - 1, BasePoint.Y + SegHeight / 2 + 2)-(BasePoint.X + SegWidth - 1, BasePoint.Y + SegHeight)
            p.Line (BasePoint.X + SegWidth - 2, BasePoint.Y + SegHeight / 2 + 1)-(BasePoint.X + SegWidth - 2, BasePoint.Y + SegHeight - 1)
            p.Line (BasePoint.X + SegWidth - 3, BasePoint.Y + SegHeight / 2 + 2)-(BasePoint.X + SegWidth - 3, BasePoint.Y + SegHeight - 2)
        Case 4
            p.Line (BasePoint.X + 3, BasePoint.Y + SegHeight - 2)-(BasePoint.X + SegWidth - 3, BasePoint.Y + SegHeight - 2)
            p.Line (BasePoint.X + 2, BasePoint.Y + SegHeight - 1)-(BasePoint.X + SegWidth - 2, BasePoint.Y + SegHeight - 1)
            p.Line (BasePoint.X + 1, BasePoint.Y + SegHeight)-(BasePoint.X + SegWidth - 1, BasePoint.Y + SegHeight)
        Case 5
            p.Line (BasePoint.X, BasePoint.Y + SegHeight / 2 + 1)-(BasePoint.X, BasePoint.Y + SegHeight)
            p.Line (BasePoint.X + 1, BasePoint.Y + SegHeight / 2)-(BasePoint.X + 1, BasePoint.Y + SegHeight - 1)
            p.Line (BasePoint.X + 2, BasePoint.Y + SegHeight / 2 + 1)-(BasePoint.X + 2, BasePoint.Y + SegHeight - 2)
        Case 6
            p.Line (BasePoint.X, BasePoint.Y + 1)-(BasePoint.X, BasePoint.Y + SegHeight / 2 - 1)
            p.Line (BasePoint.X + 1, BasePoint.Y + 2)-(BasePoint.X + 1, BasePoint.Y + SegHeight / 2)
            p.Line (BasePoint.X + 2, BasePoint.Y + 3)-(BasePoint.X + 2, BasePoint.Y + SegHeight / 2 - 1)
        Case 7
            p.Line (BasePoint.X + 3, BasePoint.Y + SegHeight / 2 - 1)-(BasePoint.X + SegWidth - 3, BasePoint.Y + SegHeight / 2 - 1)
            p.Line (BasePoint.X + 2, BasePoint.Y + SegHeight / 2)-(BasePoint.X + SegWidth - 2, BasePoint.Y + SegHeight / 2)
            p.Line (BasePoint.X + 3, BasePoint.Y + SegHeight / 2 + 1)-(BasePoint.X + SegWidth - 3, BasePoint.Y + SegHeight / 2 + 1)
    End Select
End Sub

④、画1-9数字的过程

Public Sub DrawNumber(ByVal Number As Integer)
    Select Case Number
        Case 0
            DrawSegment (1)
            DrawSegment (2)
            DrawSegment (5)
            DrawSegment (6)
            DrawSegment (4)
            DrawSegment (3)
        Case 1
            DrawSegment (2)
            DrawSegment (3)
        Case 2
            DrawSegment (1)
            DrawSegment (2)
            DrawSegment (5)
            DrawSegment (7)
            DrawSegment (4)
        Case 3
            DrawSegment (3)
            DrawSegment (1)
            DrawSegment (2)
            DrawSegment (7)
            DrawSegment (4)
        Case 4
            DrawSegment (2)
            DrawSegment (6)
            DrawSegment (7)
            DrawSegment (3)
        Case 5
            DrawSegment (1)
            DrawSegment (6)
            DrawSegment (3)
            DrawSegment (7)
            DrawSegment (4)
        Case 6
            DrawSegment (1)
            DrawSegment (6)
            DrawSegment (5)
            DrawSegment (7)
            DrawSegment (4)
            DrawSegment (3)
        Case 7
            DrawSegment (1)
            DrawSegment (2)
            DrawSegment (3)
        Case 8
            DrawSegment (1)
            DrawSegment (2)
            DrawSegment (3)
            DrawSegment (4)
            DrawSegment (5)
            DrawSegment (6)
            DrawSegment (7)
        Case 9
            DrawSegment (1)
            DrawSegment (2)
            DrawSegment (3)
            DrawSegment (7)
            DrawSegment (6)
    End Select
End Sub

⑤ 对象实例化和初始化

Public Sub NewLCD(PBox As PictureBox)

   Set p = PBox
   p.ScaleMode = 3               ' pixel
   p.AutoRedraw = True
   BasePoint.X = 2
   BasePoint.Y = 2
   SegHeight = p.ScaleHeight - 6
   SegWidth = (SegHeight / 2) + 2

End Sub

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值