IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

VB.NET Discussion :

Progressbar listview1, afficher sur les 5 listviewsubitem?


Sujet :

VB.NET

  1. #1
    Membre éprouvé
    Homme Profil pro
    Étudiant
    Inscrit en
    Janvier 2018
    Messages
    323
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Janvier 2018
    Messages : 323
    Par défaut Progressbar listview1, afficher sur les 5 listviewsubitem?
    Bonjour,

    je voudrais afficher progressbar dans listview1 mais mon souci j'arrive afficher sur les 5 listviewsubitems.

    Nom : Capture.PNG
Affichages : 172
Taille : 4,6 Ko

    mon code :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    Public Class Form1
        Dim pb As New ProgressBar
        Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
            For i = 0 To 5
                Dim lvi As New ListViewItem(i)
                lvi.SubItems.Add("")
                ListView1.Items.Add(lvi)
                ListView1.Controls.Add(Listview_Progressbar(ListView1, 1))
            Next
        End Sub
     
        Private Function Listview_Progressbar(lvl As ListView, Index As Integer) As ProgressBar
            pb.Minimum = 0
            pb.Maximum = 100
            pb.Value = 50
            pb.Parent = lvl
            Dim rt As New Rectangle
            rt = lvl.Items(lvl.Items.Count - 1).SubItems(Index).Bounds
            pb.SetBounds(rt.X, rt.Y, rt.Width, rt.Height)
            Return pb
        End Function
    End Class
    Pouvez-vous me dire comment afficher sur les 5 listviewsubitem? merci d'avance

  2. #2
    Membre éprouvé
    Homme Profil pro
    Étudiant
    Inscrit en
    Janvier 2018
    Messages
    323
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Janvier 2018
    Messages : 323
    Par défaut
    je viens trouver la solution a mon erreur :
    Nom : Capture.PNG
Affichages : 128
Taille : 5,3 Ko

    voici mon code :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    Public Class Form1
        Dim value As Integer = 50
        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(Listview_Progressbar(ListView1, i, 1, value))
                Itcontrol.Add(listview_button(ListView1, i, 2))
                value += 5
            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 listview_button(lvl As ListView, ListViewItemIndex As Integer, ColumnIndex As Integer) As Button
            Dim btn As New Button
            btn.Text = "Télécharger"
            AddHandler btn.Click, AddressOf Downloader
            btn.Parent = lvl
            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 + 3)
            Return btn
        End Function
     
        Private Sub Downloader(sender As Object, e As EventArgs)
     
        End Sub
     
        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
     
    End Class
    j'ai juste une derniere question. comment recupere dans listview1.items(0).subitems.text en cliquent sur la buttons avec msgbox?
    Merci d'avance.

  3. #3
    Membre éprouvé
    Homme Profil pro
    Étudiant
    Inscrit en
    Janvier 2018
    Messages
    323
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Janvier 2018
    Messages : 323
    Par défaut
    j'ai ajouter dans listview1 : progressbar,button,combobox,textbox.

    Nom : Capture.PNG
Affichages : 101
Taille : 8,9 Ko

    mon code :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    la class Myprogressbar :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    Class MyProgressBar
        Inherits ProgressBar
     
        Dim _color As Color = Color.Blue
        Property color() As Color
            Get
                Return _color
            End Get
            Set(ByVal value As Color)
                _color = value
            End Set
        End Property
     
        Dim _font As Font
        Property MyFont() As Font
            Get
                Return _font
            End Get
            Set(value As Font)
                _font = value
            End Set
        End Property
     
        Public Sub New()
            Me.SetStyle(ControlStyles.OptimizedDoubleBuffer Or ControlStyles.UserPaint, True)
        End Sub
     
        Protected Overrides Sub OnPaint(e As PaintEventArgs)
            ProgressBarRenderer.DrawHorizontalBar(e.Graphics, New Rectangle(0, 0, Me.Width, Me.Height))
            Dim ProgressWidth As Integer = CInt((Me.Width / (Me.Maximum - Me.Minimum)) * Me.Value)
            ProgressBarRenderer.DrawHorizontalChunks(e.Graphics, New Rectangle(0, 0, ProgressWidth, Me.Height))
            Dim ProgressPercent As Integer = CInt(((Me.Maximum - Me.Minimum) / 100) * Me.Value)
            TextRenderer.DrawText(e.Graphics, ProgressPercent.ToString & "%", _font, New Rectangle(0, 2, Me.Width, Me.Height), _color, TextFormatFlags.HorizontalCenter Or TextFormatFlags.VerticalCenter)
            MyBase.OnPaint(e)
        End Sub
    End Class
    ma question, je voudrais savoir si c'est possible avoir un espace entre progressbar,buttons....etc dans listview1. avez-vous une idée comment faire un espace entre progressbar,button...etc? merci d'avance.

  4. #4
    Membre éprouvé
    Homme Profil pro
    Étudiant
    Inscrit en
    Janvier 2018
    Messages
    323
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Janvier 2018
    Messages : 323
    Par défaut
    Bonjour, je viens trouver la solution a mon problème avec un espace entre progressbar,buttons...etc

    voici en image :
    Nom : Listview1.png
Affichages : 87
Taille : 7,0 Ko

    la class avec listviewEx :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    95
    96
    97
    98
    99
    100
    Imports System.Runtime.InteropServices
    Imports System.ComponentModel
     
     
    Namespace ExtendedControls
        Public Class ListViewEx
            Inherits ListView
     
            <StructLayout(LayoutKind.Sequential)>
            Structure DRAWITEMSTRUCT
                Public ctlType As Integer
                Public ctlID As Integer
                Public itemID As Integer
                Public itemAction As Integer
                Public itemState As Integer
                Public hWndItem As IntPtr
                Public hDC As IntPtr
                Public rcLeft As Integer
                Public rcTop As Integer
                Public rcRight As Integer
                Public rcBottom As Integer
                Public itemData As IntPtr
            End Structure
     
            Const LVS_OWNERDRAWFIXED As Integer = &H400
            Const WM_SHOWWINDOW As Integer = &H18
            Const WM_DRAWITEM As Integer = &H2B
            Const WM_MEASUREITEM As Integer = &H2C
            Const WM_REFLECT As Integer = &H2000
            Private mb_Measured As Boolean = False
            Private ms32_RowHeight As Integer = 14
     
            Public Sub New()
                SetStyle(ControlStyles.OptimizedDoubleBuffer Or ControlStyles.AllPaintingInWmPaint, True)
                Me.OwnerDraw = False
                Me.View = Windows.Forms.View.Details
                Me.GridLines = True
            End Sub
     
            <Category("Appearance")>
            <Description("Définit la hauteur des lignes ListView dans la vue Détails en pixels.")>
            Public Property RowHeight As Integer
                Get
                    Return ms32_RowHeight
                End Get
                Set(ByVal value As Integer)
                    ms32_RowHeight = value
                    Me.Invalidate()
                End Set
            End Property
     
            Protected Overrides ReadOnly Property CreateParams As CreateParams
                Get
                    Dim k_Params As CreateParams = MyBase.CreateParams
                    k_Params.Style = k_Params.Style Or LVS_OWNERDRAWFIXED
                    Return k_Params
                End Get
            End Property
     
            Protected Overrides Sub WndProc(ByRef k_Msg As Message)
                MyBase.WndProc(k_Msg)
                Select Case k_Msg.Msg
                    Case WM_REFLECT + WM_MEASUREITEM
                        mb_Measured = True
                        Marshal.WriteInt32(k_Msg.LParam + 4 * Marshal.SizeOf(GetType(Integer)), ms32_RowHeight)
                        k_Msg.Result = CType(1, IntPtr)
                        Exit Select
                    Case WM_REFLECT + WM_DRAWITEM
                        Dim k_Draw As DRAWITEMSTRUCT = CType(k_Msg.GetLParam(GetType(DRAWITEMSTRUCT)), DRAWITEMSTRUCT)
     
                        Using i_Graph As Graphics = Graphics.FromHdc(k_Draw.hDC)
                            Dim i_Item As ListViewItem = Items(k_Draw.itemID)
                            Dim c_BackColor As Color = i_Item.BackColor
                            If i_Item.Selected Then c_BackColor = SystemColors.Highlight
                            If Not Enabled Then c_BackColor = SystemColors.Control
     
                            Using i_BackBrush As SolidBrush = New SolidBrush(c_BackColor)
                                i_Graph.FillRectangle(i_BackBrush, i_Item.Bounds)
                            End Using
                            For S As Integer = 0 To i_Item.SubItems.Count - 1
                                Dim i_SubItem As ListViewItem.ListViewSubItem = i_Item.SubItems(S)
                                Dim k_Bounds As Rectangle = If((S > 0), i_SubItem.Bounds, i_Item.GetBounds(ItemBoundsPortion.Label))
                                Dim c_ForeColor As Color = i_SubItem.ForeColor
                                If i_Item.Selected Then c_ForeColor = SystemColors.HighlightText
                                If Not Enabled Then c_ForeColor = SystemColors.ControlText
                                Dim e_Flags As TextFormatFlags = TextFormatFlags.NoPrefix Or TextFormatFlags.EndEllipsis Or TextFormatFlags.VerticalCenter Or TextFormatFlags.SingleLine
                                Select Case Columns(S).TextAlign
                                    Case HorizontalAlignment.Center
                                        e_Flags = e_Flags Or TextFormatFlags.HorizontalCenter
                                    Case HorizontalAlignment.Right
                                        e_Flags = e_Flags Or TextFormatFlags.Right
                                End Select
                                TextRenderer.DrawText(i_Graph, i_SubItem.Text, i_SubItem.Font, k_Bounds, c_ForeColor, e_Flags)
                            Next
                        End Using
                        Exit Select
                End Select
            End Sub
        End Class
    End Namespace
    Il faudra jouer la taille que vous voulez avec RowHeight = 14,16,20,25 ....etc c'est a vous de choisir la taille que vous voulez avec GridLines.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Probleme de ProgressBar
    Par bosslex dans le forum Interfaces Graphiques en Java
    Réponses: 4
    Dernier message: 26/12/2009, 11h35
  2. Probleme avec ProgressBar de Richfaces
    Par nawfal_saber dans le forum JSF
    Réponses: 1
    Dernier message: 30/07/2008, 13h45
  3. probleme progressbar vb6
    Par patou60110 dans le forum VB 6 et antérieur
    Réponses: 5
    Dernier message: 22/11/2007, 17h32
  4. probleme avec ProgressBar
    Par k_boy dans le forum VC++ .NET
    Réponses: 8
    Dernier message: 15/09/2006, 17h19
  5. [VB.NET] [ProgressBar] Probleme de "refresh"
    Par Aspic dans le forum Windows Forms
    Réponses: 3
    Dernier message: 06/05/2006, 16h15

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo