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 90 91 92 93 94
| Public Class Form1
Dim Itcontrol As New List(Of Control)
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
ListView1.Items.Clear()
ControlDispose()
For i = 0 To 5
Dim lvi As New ListViewItem(New String() {i, "", ""})
ListView1.Items.Add(lvi)
Itcontrol.Add(AddProgressbar(ListView1, i, 1))
Itcontrol.Add(AddButton(ListView1, i, 2, Color.Blue))
....etc
Next
End Sub
Private Function Listview_Progressbar(lvl As ListView, ListViewItemIndex As Integer, ColumnIndex As Integer, valeur As Integer) As ProgressBar
Dim pb As New ProgressBar
Dim rt As New Rectangle
rt = lvl.Items(ListViewItemIndex).Bounds()
rt.Width = lvl.Columns(ColumnIndex).Width
If ColumnIndex > 0 Then
rt.X = rt.X + lvl.Columns(ColumnIndex - 1).Width
End If
pb.Minimum = 0
pb.Maximum = 100
pb.Value = valeur
pb.Parent = lvl
pb.SetBounds(rt.X, rt.Y, rt.Width, rt.Height + 2)
pb.Visible = True
Return pb
End Function
Private Function AddButton(lvl As ListView, ListViewItemIndex As Integer, ColumnIndex As Integer, color As Color) As Button
Dim btn As New Button
btn.Text = "Button " & ListViewItemIndex.ToString
AddHandler btn.Click, AddressOf Allbuttons
btn.Parent = lvl
btn.ForeColor = color
btn.Tag = ListViewItemIndex
Dim ps2 As ListViewItem.ListViewSubItem
ps2 = lvl.Items(ListViewItemIndex).SubItems(ColumnIndex)
Dim rt2 As New Rectangle
rt2 = ps2.Bounds
btn.SetBounds(rt2.X, rt2.Y, rt2.Width, rt2.Height + 4)
Return btn
End Function
Private Sub Allbuttons(sender As Object, e As EventArgs)
Dim btn As Button = CType(sender, Button)
If btn.Tag > -1 Then
UpdateProgressBar(ListView1, btn.Tag, 75)
End If
End Sub
Private Sub UpdateProgressBar(LVI As ListView, index As Integer, pourcentage As Integer)
For Each item As Control In LVI.Controls.OfType(Of ProgressBar)()
If item.Name = index Then
Dim pb As ProgressBar = CType(item, ProgressBar)
If pb IsNot Nothing Then pb.Value = pourcentage
End If
Next
End Sub
Private Function AddProgressbar(lvl As ListView, ListViewItemIndex As Integer, ColumnIndex As Integer) As ProgressBar
Dim pb As New MyProgressBar
Dim rt As New Rectangle
rt = lvl.Items(ListViewItemIndex).Bounds()
rt.Width = lvl.Columns(ColumnIndex).Width
If ColumnIndex > 0 Then
rt.X = rt.X + lvl.Columns(ColumnIndex - 1).Width
End If
pb.Minimum = 0
pb.Maximum = 100
pb.Name = ListViewItemIndex
pb.Parent = lvl
pb.SetBounds(rt.X, rt.Y, rt.Width, rt.Height + 4)
pb.Visible = True
pb.color = Color.Blue
pb.MyFont = New Font("Microsoft Sans Serif", 9, FontStyle.Regular)
Return pb
End Function
Private Sub ControlDispose()
For count = 0 To Itcontrol.Count - 1 Step +1
Itcontrol(count).Dispose()
Next
If Itcontrol.Count > 0 Then
Itcontrol.Clear()
End If
End Sub
...etc
End Class |
Partager