Alejandro Acuña
2024-08-12 1876e65234c20209001178705cfa50d8f9ded67a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
'***************************************************************************
'* ClassSosPhoneList                                                       *
'*                                                                         *
'* This class expands the native ListBox with some funcionality as the     *
'* capability to draw the text in various colors etc wich is used to       *
'* represent the different states of the sos phones.                       *
'*                                                                         *
'* EQUITEL C.V. February 2007                                         ALMDI*
'***************************************************************************
Public Class ClassSosPhoneList
    Inherits System.Windows.Forms.ListBox
 
    Delegate Sub RefreshCallBack()
 
    Private Sub myClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Click
        Refresh()
    End Sub
 
    Private Sub myDrawItem(ByVal sender As Object, ByVal e As DrawItemEventArgs) Handles MyBase.DrawItem
        Dim g As Graphics = Graphics.FromHwnd(MyBase.Handle)
        Dim sf As StringFormat = New StringFormat(StringFormat.GenericTypographic)
 
        Dim P As ClassSosPhone
        Dim TextPen As Brush
        Dim S As String
        Dim F As Font
 
        If MyBase.Items.Count >= (e.Index + 1) Then
            P = MyBase.Items(e.Index)
            S = P.Name
 
            e.DrawBackground()
            e.DrawFocusRectangle()
            'Choose the appropiate drawing color depending on the selection
            'and te status of the sos phone
            If e.Index = MyBase.SelectedIndex Then
                If P.Connected Then
                    TextPen = New SolidBrush(Color.LightGreen)
                Else
                    TextPen = New SolidBrush(Color.Gray)
                End If
            Else
                If P.Connected Then
                    TextPen = New SolidBrush(Color.Green)
                Else
                    TextPen = New SolidBrush(Color.Gray)
                End If
            End If
            'Draws a rectangle to enclose each item of the list
            e.Graphics.DrawRectangle(Pens.Black, e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height)
            'Draw the text
            If P.Connected Then
                F = New Font(MyBase.Font, FontStyle.Bold)
            Else
                F = MyBase.Font
            End If
            e.Graphics.DrawString(P.Name, F, TextPen, e.Bounds.X, e.Bounds.Y)
        End If
    End Sub
 
    Private Sub myMeasureItem(ByVal sender As Object, ByVal e As MeasureItemEventArgs) Handles MyBase.MeasureItem
        Dim g As Graphics = Graphics.FromHwnd(MyBase.Handle)
        Dim sf As StringFormat = New StringFormat(StringFormat.GenericTypographic)
        Dim size As SizeF
        Dim height As Single = 0
        Dim oFont As Font
        Dim P As ClassSosPhone
 
 
        'measure the height of what you are about to draw
        'and let the listbox know this
        If MyBase.Items.Count >= (e.Index + 1) Then
            oFont = MyBase.Font
            P = MyBase.Items(e.Index)
            size = g.MeasureString(P.Name, oFont, 500, sf)
            height = size.Height + 5
            e.ItemHeight = height
        End If
    End Sub
 
    Public Sub MyRefresh()
        If InvokeRequired Then
            Dim d As New RefreshCallBack(AddressOf MyRefresh)
            Me.Invoke(d)
        Else
            Me.Refresh()
        End If
    End Sub
End Class