Listview con progress Downloader

Iniciado por 79137913, 23 Julio 2014, 20:43 PM

0 Miembros y 1 Visitante están viendo este tema.

79137913

HOLA!!!

Queria saber si alguien tenia un ejemplo de lo de arriba para vbnet gracias!

GRACIAS POR LEER!!!
"Como no se puede igualar a Dios, ya he decidido que hacer, ¡SUPERARLO!"
"La peor de las ignorancias es no saber corregirlas"

79137913                          *Shadow Scouts Team*

Eleкtro

#1
Hola, lo que pides no es un tema sencillo de resumir en pocas palabras.

Hace mucho tiempo, en mis inicios, subclaseé el Listviewe y cada cierto tiempo le fui añadiendo características de todo tipo, como por ejemplo la barra de progreso en la que estás interesado.

Estos son los miembros que te interesarán de mi user-control:



ProgressBar_Enabled
Progressbar_Column
ProgressBar_BackColor
ProgressBar_BorderColor
ProgressBar_FillColor1
ProgressBar_FillColor2
ProgressPercent
ProgressPercent_Decimal
ProgressPercent_Text
ProgressPercent_Text_Allignment
ProgressPercent_Text_Trimming
ProgressPercent_Font
ProgressPercent_Forecolor


Nótese las propiedades 'ProgressBar_Enabled' y 'Progressbar_Column', la primera propiedad determina si la barra de progreso se debe dibujar, y la segunda propiedad determina la columna en la que se dibujará la barra de progreso (en todas las celdas de la columna especificada).

PD: De todas formas esto es un proyecto sin terminar, porque se usa la misma barra de progreso para cada fila, es decir el porcentaje afecta a todas las barras, le daré un repaso al código para ver si subclaseando el 'ListViewItem' y/o 'ListViewItem.ListViewSubItem' puedo hacerle los cambios necesarios.




Aquí tienes el source completo:

· ElektroListview

Y aquí un ejemplo mucho más reducido que guardé hasta ahora:

Código (vbnet) [Seleccionar]
#Region " [ListView] Draw ProgressBar "

   ' [ [ListView] Draw ProgressBar ]

   Private Listview_Column As Integer = 4 ' The column index to draw the ProgressBar

   Private Percent As Double = 0 ' The progress percentage
   Private Percent_DecimalFactor As Short = 1 ' Example: 0.1
   Private Percent_Text As String = "% Done" ' Example: 0.1% Done
   Private Percent_Forecolor As Brush = Brushes.Black
   Private Percent_Font As Font = Me.Font

   Private ProgressBar_BackColor As Brush = Brushes.White
   Private ProgressBar_BorderColor As Pen = Pens.LightGray
   Private ProgressBar_FillColor1 As Color = Color.YellowGreen
   Private ProgressBar_FillColor2 As Color = Color.White

   ' ListView [Layout]
   Private Sub ListView1_Layout(sender As Object, e As LayoutEventArgs) _
   Handles ListView1.Layout

       ' Set Listview OwnerDraw to True, so we can draw the progressbar.
       ListView1.OwnerDraw = True

   End Sub

   ' ListView [DrawColumnHeader]
   Private Sub ListView_DrawColumnHeader(ByVal sender As Object, ByVal e As DrawListViewColumnHeaderEventArgs) _
   Handles ListView1.DrawColumnHeader

       e.DrawDefault = True ' Draw default ColumnHeader.

   End Sub

   ' ListView [DrawItem]
   Private Sub ListView_DrawItem(ByVal sender As Object, ByVal e As DrawListViewItemEventArgs) _
   Handles ListView1.DrawItem

       e.DrawDefault = False ' Draw default main item.

   End Sub

   ' ListView [DrawSubItem]
   Private Sub ListView_DrawSubItem(ByVal sender As Object, ByVal e As DrawListViewSubItemEventArgs) _
   Handles ListView1.DrawSubItem

       If (e.ItemState And ListViewItemStates.Selected) <> 0 Then
           ' Item is highlighted.
           e.Graphics.FillRectangle(SystemBrushes.Highlight, e.Bounds)
       End If

       ' Draw the progressbar.
       If e.ColumnIndex = Listview_Column Then

           ' Center the text in the progressbar.
           Dim sf As New StringFormat
           sf.Alignment = StringAlignment.Center

           ' Background color of the progressbar is white.
           e.Graphics.FillRectangle(ProgressBar_BackColor, e.Bounds)

           ' Percentage of the progressbar to fill.
           Dim FillPercent As Integer = CInt(((Percent) / 100) * (e.Bounds.Width - 2))

           ' This creates a nice color gradient to fill.
           Dim brGradient As Brush = _
               New System.Drawing.Drawing2D.LinearGradientBrush(New Rectangle(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height), _
                                                                ProgressBar_FillColor1, ProgressBar_FillColor2, 270, True)
           ' Draw the actual progressbar.
           e.Graphics.FillRectangle(brGradient, _
                                    e.Bounds.X + 1, e.Bounds.Y + 2, _
                                    FillPercent, e.Bounds.Height - 3)

           ' Draw the percentage number and percent sign.
           ' NOTE: make sure that e.SubItem.Text only contains a number or an error will occur.
           e.Graphics.DrawString(Percent.ToString("n" & Percent_DecimalFactor) & Percent_Text, _
                                 Percent_Font, Percent_Forecolor, _
                                 CSng(e.Bounds.X + (e.Bounds.Width / 2)), e.Bounds.Y + 3, _
                                 sf)

           ' Draw a light gray rectangle/border around the progressbar.
           e.Graphics.DrawRectangle(ProgressBar_BorderColor, _
                                    e.Bounds.X, e.Bounds.Y + 1, _
                                    e.Bounds.Width - 1, e.Bounds.Height - 2)
       Else
           e.DrawDefault = True

       End If

   End Sub

#End Region








79137913

HOLA!!!

Buen dato!

Voy a intentar implementar tu code.

GRACIAS POR LEER!!!
"Como no se puede igualar a Dios, ya he decidido que hacer, ¡SUPERARLO!"
"La peor de las ignorancias es no saber corregirlas"

79137913                          *Shadow Scouts Team*