home *** CD-ROM | disk | FTP | other *** search
- VERSION 5.00
- Begin VB.UserControl EZPort
- Appearance = 0 'Flat
- BackColor = &H80000005&
- BackStyle = 0 'Transparent
- ClientHeight = 855
- ClientLeft = 0
- ClientTop = 0
- ClientWidth = 735
- ClipControls = 0 'False
- ScaleHeight = 855
- ScaleWidth = 735
- ToolboxBitmap = "ezport.ctx":0000
- Begin VB.PictureBox picDot
- Appearance = 0 'Flat
- BackColor = &H00C0FFC0&
- BorderStyle = 0 'None
- DrawStyle = 5 'Transparent
- FillColor = &H00FFFFFF&
- FillStyle = 0 'Solid
- ForeColor = &H00000000&
- Height = 108
- Index = 1
- Left = 165
- ScaleHeight = 105
- ScaleWidth = 135
- TabIndex = 1
- TabStop = 0 'False
- Top = 525
- Width = 132
- End
- Begin VB.Image imgPorts
- Appearance = 0 'Flat
- Height = 300
- Index = 1
- Left = 75
- Picture = "ezport.ctx":0312
- Top = 450
- Width = 315
- End
- Begin VB.Label lblPort
- Alignment = 2 'Center
- Appearance = 0 'Flat
- AutoSize = -1 'True
- BackColor = &H80000005&
- Caption = "lbl"
- ForeColor = &H80000008&
- Height = 195
- Index = 1
- Left = 105
- TabIndex = 0
- Top = 105
- Width = 165
- End
- End
- Attribute VB_Name = "EZPort"
- Attribute VB_GlobalNameSpace = False
- Attribute VB_Creatable = True
- Attribute VB_PredeclaredId = False
- Attribute VB_Exposed = True
- Option Explicit
- Option Base 1
-
- Public Enum PortStates
- stActive = 1
- stInactive = 2
- stOff = 3
- End Enum
- Dim m_ActiveColor As OLE_COLOR
- Dim m_InactiveColor As OLE_COLOR
- Dim m_OffColor As OLE_COLOR
- Dim mblnEnabled As Boolean
- Dim mintPorts As Integer
-
- Const mdefActive As Long = &HFF00&
- Const mdefInactive As Long = &HC0FFC0
- Const mdefOff As Long = &H0&
- Public Event Click(Left As Long, top As Long, Port As Integer)
- Attribute Click.VB_Description = "Event raised when port is clicked. Left center, Top center, and Port number are returned"
- Public Event DblClick(Port As Integer, State As PortStates)
- Attribute DblClick.VB_Description = "Event raised when port is double clicked. Port number and current state of port are returned."
-
- Private Sub UserControl_InitProperties()
- mintPorts = 4
- lblPort(1).BackColor = Ambient.BackColor
- With Me
- .ActiveColor = mdefActive
- .InactiveColor = mdefInactive
- .OffColor = mdefOff
- .Ports = mintPorts
- Set .Font = Ambient.Font
- .Border = False
- End With
- Call StandardPortLabels
- mblnEnabled = True
- With imgPorts(mintPorts)
- UserControl.Width = .Left + .Width
- End With
- End Sub
-
- Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
- Dim intX As Integer
- Call PropBag.WriteProperty("Font", Font, Ambient.Font)
- Call PropBag.WriteProperty("Ports", mintPorts, 4)
- Call PropBag.WriteProperty("ActiveColor", m_ActiveColor, mdefActive)
- Call PropBag.WriteProperty("InactiveColor", m_InactiveColor, mdefInactive)
- Call PropBag.WriteProperty("OffColor", m_OffColor, mdefOff)
- Call PropBag.WriteProperty("Enabled", mblnEnabled, True)
- Call PropBag.WriteProperty("Border", Me.Border, False)
- For intX = 1 To mintPorts
- Call PropBag.WriteProperty("PortCaption", _
- lblPort(intX).Caption, Trim(Str(intX)) & "x")
- Next
- End Sub
-
- Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
- Dim intX As Integer
- With Me
- .ActiveColor = PropBag.ReadProperty("ActiveColor", mdefActive)
- .InactiveColor = PropBag.ReadProperty("InactiveColor", mdefInactive)
- .OffColor = PropBag.ReadProperty("OffColor", mdefOff)
- .Ports = PropBag.ReadProperty("Ports", 4)
- .Enabled = PropBag.ReadProperty("Enabled", True)
- .Border = PropBag.ReadProperty("Border", False)
- For intX = 1 To mintPorts
- .PortCaption(intX) = PropBag.ReadProperty("PortCaption", Trim(Str(intX)) & "x")
- Next
- End With
- Set Font = PropBag.ReadProperty("Font", Ambient.Font)
- lblPort(1).BackColor = Ambient.BackColor
- End Sub
- Private Sub UserControl_Resize()
- Dim intX As Integer
- Dim lngLeft As Long
-
- For intX = 1 To imgPorts.Count
- With imgPorts(intX)
- lngLeft = (intX - 1) * .Width
- .Move lngLeft, lblPort(1).Height
- picDot(intX).Move lngLeft + 90, .top + 60
- lblPort(intX).Move lngLeft, 0
- End With
- Call ShowControl(imgPorts(intX), True)
- Call ShowControl(picDot(intX), True)
- Call ShowControl(lblPort(intX), True)
- Next
- With UserControl
- .Height = lblPort(1).Height + imgPorts(1).Height
- .Width = lngLeft + imgPorts(1).Width
- End With
-
- End Sub
-
- Public Property Let Border(ByVal New_Border As Boolean)
- Attribute Border.VB_Description = "Sets/returns border status of control"
- With UserControl
- If New_Border = False Then
- .BorderStyle = 0
- Else
- .BorderStyle = 1
- End If
- End With
- PropertyChanged "Border"
- End Property
-
- Public Property Get Border() As Boolean
- With UserControl
- If .BorderStyle = 0 Then
- Border = False
- Else
- Border = True
- End If
- End With
- End Property
-
- Public Property Get Font() As Font
- Attribute Font.VB_Description = "Set/return font of port lables"
- Set Font = lblPort(1).Font
- End Property
-
- Public Property Set Font(ByVal NewFont As Font)
- Dim intX As Integer
- For intX = 1 To mintPorts
- Set lblPort(intX).Font = NewFont
- Next
- Call UserControl_Resize
- PropertyChanged "Font"
- End Property
-
- Public Property Get ActiveColor() As OLE_COLOR
- Attribute ActiveColor.VB_Description = "Sets/returns active color of ports in control"
- ActiveColor = m_ActiveColor
- End Property
-
- Public Property Let ActiveColor(ByVal New_ActiveColor As OLE_COLOR)
- m_ActiveColor = New_ActiveColor
- PropertyChanged "ActiveColor"
- End Property
-
- Public Property Get InactiveColor() As OLE_COLOR
- Attribute InactiveColor.VB_Description = "Sets/returns inactive color of ports in control"
- InactiveColor = m_InactiveColor
- End Property
-
- Public Property Let InactiveColor(ByVal New_InactiveColor As OLE_COLOR)
- m_InactiveColor = New_InactiveColor
- PropertyChanged "InactiveColor"
- End Property
-
- Public Property Get OffColor() As OLE_COLOR
- Attribute OffColor.VB_Description = "Sets/returns off color of ports in control"
- OffColor = m_OffColor
- End Property
-
- Public Property Let OffColor(ByVal New_OffColor As OLE_COLOR)
- m_OffColor = New_OffColor
- PropertyChanged "OffColor"
- End Property
-
- Public Property Let Enabled(ByVal New_Bln As Boolean)
- Attribute Enabled.VB_Description = "Enable/Disable control"
- mblnEnabled = New_Bln
- UserControl.Enabled = New_Bln
- End Property
-
- Public Property Get Enabled() As Boolean
- Enabled = mblnEnabled
- End Property
-
- Public Property Get PortCaption(Port As Integer) As String
- Attribute PortCaption.VB_Description = "Sets/returns port label"
- PortCaption = lblPort(Port)
- End Property
-
- Public Property Let PortCaption(Port As Integer, _
- ByVal NewCaption As String)
- lblPort(Port) = NewCaption
- PropertyChanged "PortCaption"
- End Property
-
- Private Sub PortColor(pic As PictureBox, Color As OLE_COLOR)
- pic.BackColor = Color
- End Sub
- Public Sub SetAllPorts(State As PortStates)
- Attribute SetAllPorts.VB_Description = "Sets all ports in control to specified state."
- Dim intX As Integer
- Dim Color As OLE_COLOR
-
- Color = SetColor(State)
- For intX = 1 To picDot.Count
- Call PortColor(picDot(intX), Color)
- Next
- End Sub
-
- Private Function SetColor(State As PortStates) As OLE_COLOR
- Select Case State
- Case 1
- SetColor = m_ActiveColor
- Case 2
- SetColor = m_InactiveColor
- Case 3
- SetColor = m_OffColor
- End Select
- End Function
-
- Public Property Get Ports() As Long
- Attribute Ports.VB_Description = "Sets/Returns number of ports in control."
- Ports = mintPorts
- End Property
-
- Public Property Let Ports(ByVal New_Ports As Long)
- Dim intX As Integer
- Dim intCnt As Integer
- intCnt = picDot.Count - 1
-
- If New_Ports < 1 Then New_Ports = 1
- If New_Ports > 24 Then New_Ports = 24
- New_Ports = New_Ports - 1
- If intCnt = New_Ports Then Exit Property
-
- intX = New_Ports - intCnt
- If intX < 0 Then
- Call RemovePorts(Abs(intX))
- Else
- Call AddPorts(intX)
- End If
-
- mintPorts = picDot.Count
- Call SetAllPorts(stActive)
- Call UserControl_Resize
- PropertyChanged "Ports"
- End Property
- Private Sub AddPorts(intX As Integer)
- Dim intY As Integer
- Dim intCnt As Integer
-
- intCnt = picDot.Count
- For intY = intCnt + 1 To (intX + intCnt)
- Load imgPorts(intY)
- Load picDot(intY)
- Load lblPort(intY)
- With lblPort(intY)
- .BackColor = Ambient.BackColor
- .Caption = Trim(Str(intY)) & "x"
- End With
- Next
- Call UserControl_Resize
- End Sub
- Private Sub RemovePorts(intX As Integer)
- Dim intCnt As Integer
- Dim intC As Integer
- intC = picDot.Count
- Do While picDot.Count > (intC - intX)
- intCnt = picDot.Count
- Unload imgPorts(intCnt)
- Unload picDot(intCnt)
- Unload lblPort(intCnt)
- Loop
- Call UserControl_Resize
- End Sub
- Public Property Get PortState(ByVal Port As Integer) _
- As PortStates
- Attribute PortState.VB_Description = "Sets/Returns state of port specified. Active, inactive or off"
- Select Case picDot(Port).BackColor
- Case m_ActiveColor
- PortState = stActive
- Case m_InactiveColor
- PortState = stInactive
- Case m_OffColor
- PortState = stOff
- End Select
- End Property
-
- Public Property Let PortState(ByVal Port As Integer, _
- State As PortStates)
- If State < stActive Then State = stActive
- If State > stOff Then State = stOff
-
- Call PortColor(picDot(Port), SetColor(State))
- PropertyChanged "PortState"
- End Property
-
- Private Sub ShowControl(ctl As Control, Show As Boolean)
- With ctl
- If Show Then
- If Not .Visible Then .Visible = True
- Else
- If .Visible Then .Visible = False
- End If
- End With
- End Sub
-
- Private Sub picDot_Click(Index As Integer)
- Dim lngLeft As Long
- Dim lngTop As Long
- With picDot(Index)
- lngLeft = .Left + (.Width / 2)
- lngTop = .top + (.Height / 2)
- RaiseEvent Click(lngLeft, lngTop, Index)
- End With
- End Sub
-
- Private Sub picDot_DblClick(Index As Integer)
- RaiseEvent DblClick(Index, PortState(Index))
- End Sub
-
- Public Sub LocatePort(ByVal Port As Integer, Left As Long, top As Long)
- Attribute LocatePort.VB_Description = "Returns left center and top center positon of port specified"
- With picDot(Port)
- Left = .Left + (.Width / 2)
- top = .top + (.Height / 2)
- End With
- End Sub
-
- Public Sub StandardPortLabels()
- Attribute StandardPortLabels.VB_Description = "Sets all port labels to conventional standard (1x 2x 3x ...)"
- Dim intX As Integer
- For intX = 1 To mintPorts
- lblPort(intX) = Trim(Str(intX)) & "x"
- Next
- End Sub
-
- Public Function GetPortColor(Port As Integer) As OLE_COLOR
- Attribute GetPortColor.VB_Description = "Returns color of port specified"
- GetPortColor = picDot(Port).BackColor
- End Function
-