2、电子表
①、设置当前坐标:
Private Type coodinate
X As Integer
Y As Integer
End TypeDim 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 IntegerOrigX = BasePoint.X
p.ClsWhile 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)
WendBasePoint.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) + 2End Sub