本處實做一個燈號使用者控制項,狀態數量由屬性"狀態數量"設定,
,不同狀態燈號圖片由上圖狀態圖示插入。
CODE:
Public Class PilotLight
Dim stateNum As UInteger = 2 '指示燈狀態數量
Dim statePIC As Image() = New Image(8) {} '該狀態圖示(狀態0開始)
Dim pic_sizemode As PictureBoxSizeMode = PictureBoxSizeMode.StretchImage '圖效果
Dim uniqeID As String '物件獨特ID
Dim state As UInteger = 0 '目前燈狀態
............................................
Sub New()
'使指示燈圖拉長或縮小以符合大小
InitializeComponent()
PictureBox1.SizeMode = pic_sizemode
PictureBox1.Image = statePIC(state)
' Add any initialization after the InitializeComponent() call.
End Sub
Property 狀態數量 As UInteger '最多9組 最少2組
Get
Return stateNum
End Get
Set(value As UInteger)
If value > 10 Then
stateNum = 9
ElseIf value < 2 Then
stateNum = 2
Else
stateNum = value
End If
End Set
End Property
Property 狀態圖示 As Image()
Get
Return statePIC
End Get
Set(value As Image())
statePIC = value
End Set
End Property
.............................下略