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 :

probléme caractères dans un columns


Sujet :

VB.NET

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  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 probléme caractères dans un columns
    Bonjour, je reviens faire vous pour une aide pour corriger un petite problème. quand je déplace la souris sur la columns 0 le caractères écriture change en gras ( voir image).
    en image :
    Nom : Sans titre.png
Affichages : 198
Taille : 8,0 Ko

    voici mon code complet :
    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
    Imports System.Drawing.Drawing2D
    Imports System.Windows.Forms.VisualStyles
     
    Public Class Form1
     
        Private lvEditMode As Boolean = False
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            ConfigListview()
        End Sub
     
        Private Sub ConfigListview()
            With ListView1
                .GridLines = True
                .FullRowSelect = True
                .CheckBoxes = True
                .View = View.Details
                .Scrollable = True
                .MultiSelect = False
                .BackColor = Color.Silver
                .ForeColor = Color.Black
                .OwnerDraw = True
                .Font = New Font("Microsoft Sans Serif", 12, FontStyle.Regular)
                .Columns.Add("Names", 150, HorizontalAlignment.Center)
                .Columns.Add("Nombres", 120, HorizontalAlignment.Center)
                .Columns.Add("Prix", 120, HorizontalAlignment.Center)
                .Columns.Add("Nombres", 120, HorizontalAlignment.Center)
                For i As Integer = 0 To 2
                    Dim item As New ListViewItem("Productions " & i.ToString)
                    item.SubItems.Add(i.ToString())
                    item.SubItems.Add((i + 7).ToString())
                    item.SubItems.Add((i * i).ToString())
                    .Items.Add(item)
                Next
                .Columns(0).Width = 200
                .Columns(1).Width = 120
                .Columns(2).Width = 120
                .Columns(3).Width = -2
            End With
        End Sub
     
        Private Sub ListView1_DrawColumnHeader(sender As Object, e As DrawListViewColumnHeaderEventArgs) Handles ListView1.DrawColumnHeader
            e.Graphics.FillRectangle(New SolidBrush(Color.BlueViolet), New Rectangle(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height))
            e.Graphics.DrawRectangle(New Pen(New SolidBrush(Color.White), 1), New Rectangle(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height - 1))
            e.Graphics.DrawString(e.Header.Text, e.Font, Brushes.White, e.Bounds, New StringFormat With {.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Center})
        End Sub
     
        Private Sub ListView1_DrawSubItem(sender As Object, e As DrawListViewSubItemEventArgs) Handles ListView1.DrawSubItem
            Dim lstView As ListView = TryCast(sender, ListView)
            Dim itemColor As Color = e.Item.ForeColor
            If (e.Item.Selected AndAlso Not lvEditMode) Then
                If (e.ColumnIndex = 0 OrElse lstView.FullRowSelect) Then
                    Using Brush As New SolidBrush(Color.YellowGreen)
                        e.Graphics.FillRectangle(Brush, e.Bounds)
                    End Using
                End If
            End If
            If (e.ColumnIndex = 0) Then
                Dim state As CheckBoxState = If(e.Item.Checked, CheckBoxState.CheckedNormal, CheckBoxState.UncheckedNormal)
                Dim glyphSize As Size = CheckBoxRenderer.GetGlyphSize(e.Graphics, state)
                Dim checkPad As Integer = (e.Bounds.Height - glyphSize.Height) / 2
                Dim pt As New Point(e.Bounds.X + 2, e.Bounds.Y + 2)
                Dim rect As New Rectangle(pt, New Size(18, 18))
                If state = CheckBoxState.UncheckedNormal Then
                    e.Graphics.FillRectangle(New SolidBrush(Color.Red), rect)
                    e.Graphics.DrawString("X", New Font("Verdana", 10, FontStyle.Bold), New SolidBrush(Color.White), New Rectangle(e.Bounds.X + 4, e.Bounds.Y + 3, e.Bounds.Width, e.Bounds.Height))
                ElseIf state = CheckBoxState.CheckedNormal Then
                    e.Graphics.FillRectangle(New SolidBrush(Color.Green), rect)
                    rect.Inflate(-4, -4)
                    e.Graphics.SmoothingMode = SmoothingMode.AntiAlias
                    e.Graphics.DrawLines(New Pen(New SolidBrush(Color.White), 2), New Point() {New Point(rect.Left, rect.Bottom - rect.Right / 2), New Point(rect.Left + rect.Width / 3, rect.Bottom - 2), New Point(rect.Right, rect.Top)})
                    e.Graphics.SmoothingMode = SmoothingMode.Default
                    rect.Inflate(+4, +4)
                End If
                Dim width As Integer = TextRenderer.MeasureText(Space(2), e.SubItem.Font).Width
                TextRenderer.DrawText(e.Graphics, e.SubItem.Text, e.SubItem.Font, Rectangle.Inflate(e.Bounds, -width, 0), itemColor, TextFormatFlags.LeftAndRightPadding)
            Else
                TextRenderer.DrawText(e.Graphics, e.SubItem.Text, e.SubItem.Font, e.Bounds, itemColor, TextFormatFlags.HorizontalCenter)
            End If
        End Sub
     
        Private Sub ListView1_AfterLabelEdit(sender As Object, e As LabelEditEventArgs) Handles ListView1.AfterLabelEdit
            lvEditMode = False
        End Sub
     
        Private Sub ListView1_BeforeLabelEdit(sender As Object, e As LabelEditEventArgs) Handles ListView1.BeforeLabelEdit
            lvEditMode = True
        End Sub
    End Class
    avez-vous un solution à mon problème par rapport au columns 0 du changement écritures?

  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
    Bonjour, j'ai trouvé la solution à mon problème. voici en image un amélioration du programme.
    Nom : Capture d’écran 2024-08-27 195809.png
Affichages : 138
Taille : 15,2 Ko

  3. #3
    Expert confirmé
    Avatar de popo
    Homme Profil pro
    Analyste programmeur Delphi / C#
    Inscrit en
    Mars 2005
    Messages
    2 972
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Analyste programmeur Delphi / C#
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mars 2005
    Messages : 2 972
    Par défaut
    C'est très bien d'avoir su trouver par toi même où se situait le problème.
    Et tu as eu le bon réflexe de mettre en résolu.

    Mais l'objectif du forum est d'aider la communauté.
    Donc, même si c'est trivial, c'est mieux d'indiquer la correction que tu as effectué afin que d'autres personnes avec un problème similaire puisse gagner du temps.

  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 Popo,

    Mais l'objectif du forum est d'aider la communauté.
    Donc, même si c'est trivial, c'est mieux d'indiquer la correction que tu as effectué afin que d'autres personnes avec un problème similaire puisse gagner du temps.
    ok, il y a pas de soucis, vous avez raison on est dans la communauté de problème mais dans listview1. je utilise pas GridLine = False avec mon code.

    Voici mon code complet avec checkbox Personnaliser mais c'est a vous de choisir si vous utiliser toggle ou rectangle personnaliser :
    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
    101
    102
    103
    104
    105
    Public Class Form1
     
        Private lvEditMode As Boolean = False
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            ConfigListview()
        End Sub
     
        Private Sub ConfigListview()
            With ListView1
                .GridLines = False
                .FullRowSelect = True
                .CheckBoxes = True
                .View = View.Details
                .Scrollable = True
                .MultiSelect = True
                .BackColor = Color.Silver
                .ForeColor = Color.Black
                .OwnerDraw = True
                .Cursor = Cursors.Hand
                .Font = New Font("Microsoft Sans Serif", 12, FontStyle.Regular)
                .Columns.Add("Names", 150, HorizontalAlignment.Center)
                .Columns.Add("Nombres", 120, HorizontalAlignment.Center)
                .Columns.Add("Prix", 120, HorizontalAlignment.Center)
                .Columns.Add("Nombres", 120, HorizontalAlignment.Center)
                For i As Integer = 0 To 5
                    Dim item As New ListViewItem("Productions " & i.ToString)
                    item.SubItems.Add(i.ToString())
                    item.SubItems.Add((i + 7).ToString())
                    item.SubItems.Add((i * i).ToString())
                    .Items.Add(item)
                Next
                .Columns(0).Width = 200
                .Columns(1).Width = 120
                .Columns(2).Width = 120
                .Columns(3).Width = -2
            End With
        End Sub
     
        Private Sub ListView1_DrawColumnHeader(sender As Object, e As DrawListViewColumnHeaderEventArgs) Handles ListView1.DrawColumnHeader
            e.Graphics.FillRectangle(New SolidBrush(Color.BlueViolet), New Rectangle(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height))
            e.Graphics.DrawRectangle(New Pen(New SolidBrush(Color.White), 1), New Rectangle(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height - 1))
            e.Graphics.DrawString(e.Header.Text, e.Font, Brushes.White, e.Bounds, New StringFormat With {.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Center})
        End Sub
     
        Private Sub ListView1_DrawSubItem(sender As Object, e As DrawListViewSubItemEventArgs) Handles ListView1.DrawSubItem
            If Not (e.Item.Selected AndAlso Not lvEditMode) Then
                If (e.ItemIndex Mod 2) <> 0 Then
                    e.Graphics.FillRectangle(Brushes.LightGray, e.Bounds)
                Else
                    e.Graphics.FillRectangle(Brushes.Silver, e.Bounds)
                End If
            Else
                If (e.ItemState And ListViewItemStates.Selected) <> 0 Then
                    Using Brush As New SolidBrush(Color.YellowGreen)
                        e.Graphics.FillRectangle(Brush, New Rectangle(e.Bounds.X + 43, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height))
                    End Using
                End If
            End If
            If (e.ColumnIndex = 0) Then
                Dim state As CheckBoxState = If(e.Item.Checked, CheckBoxState.CheckedNormal, CheckBoxState.UncheckedNormal)
                Dim glyphSize As Size = CheckBoxRenderer.GetGlyphSize(e.Graphics, state)
                Dim checkPad As Integer = (e.Bounds.Height - glyphSize.Height) / 8
                Dim pt As New Point(e.Bounds.X + checkPad, e.Bounds.Y - checkPad)
                Dim rect As New Rectangle(pt, New Size(20, 20))
                e.Graphics.SmoothingMode = SmoothingMode.AntiAlias
                If state = CheckBoxState.UncheckedNormal Then
                    FillRectangle(e.Graphics, New SolidBrush(Color.Red), rect, rect.Height - 15)
                    e.Graphics.FillEllipse(New SolidBrush(Color.White), New Rectangle(rect.Left + 1, rect.Y + 4, rect.Width - 5, rect.Height - 5))
                    e.Graphics.DrawString("OFF", New Font("Arial", 6, FontStyle.Bold), New SolidBrush(Color.White), New Rectangle(rect.Right - 2, rect.Y + 2, rect.Width, rect.Height), New StringFormat() With {.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Center})
                ElseIf state = CheckBoxState.CheckedNormal Then
                    FillRectangle(e.Graphics, New SolidBrush(Color.Green), rect, rect.Height - 15)
                    e.Graphics.FillEllipse(New SolidBrush(Color.White), New Rectangle(rect.Right + 3, rect.Y + 4, rect.Width - 5, rect.Height - 5))
                    e.Graphics.DrawString("ON", New Font("Arial", 6, FontStyle.Bold), New SolidBrush(Color.White), New Rectangle(rect.Left + 2, rect.Y + 3, rect.Width, rect.Height), New StringFormat() With {.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Center})
                End If
                Dim width As Integer = TextRenderer.MeasureText(Space(rect.Width / 3), e.SubItem.Font).Width
                TextRenderer.DrawText(e.Graphics, e.SubItem.Text, e.SubItem.Font, Rectangle.Inflate(e.Bounds, -width, 0), e.Item.ForeColor, TextFormatFlags.LeftAndRightPadding)
            Else
                TextRenderer.DrawText(e.Graphics, e.SubItem.Text, e.SubItem.Font, e.Bounds, e.Item.ForeColor, TextFormatFlags.HorizontalCenter)
            End If
        End Sub
     
        Private Sub FillRectangle(g As Graphics, mycolor As SolidBrush, rect As Rectangle, radius As Integer)
            Dim area As New Rectangle(rect.X, rect.Y + 2, rect.Width + 20, rect.Height)
            Dim path As New Drawing2D.GraphicsPath
            path.AddArc(area.Left, area.Top, radius * 2, radius * 2, 180, 90)
            path.AddArc(area.Right - (radius * 2), area.Top, radius * 2, radius * 2, 270, 90)
            path.AddArc(area.Right - (radius * 2), area.Bottom - (radius * 2), radius * 2, radius * 2, 0, 90)
            path.AddArc(area.Left, area.Bottom - (radius * 2), radius * 2, radius * 2, 90, 90)
            g.FillPath(mycolor, path)
        End Sub
     
        Private Sub ListView1_AfterLabelEdit(sender As Object, e As LabelEditEventArgs) Handles ListView1.AfterLabelEdit
            lvEditMode = False
        End Sub
     
        Private Sub ListView1_BeforeLabelEdit(sender As Object, e As LabelEditEventArgs) Handles ListView1.BeforeLabelEdit
            lvEditMode = True
        End Sub
     
        Private Sub ListView1_MouseClick(sender As Object, e As MouseEventArgs) Handles ListView1.MouseClick
            Dim lvi As ListViewItem = ListView1.GetItemAt(e.X, e.Y)
            If e.X > 20 AndAlso e.Y > 10 Then lvi.Checked = Not lvi.Checked
            MyBase.OnMouseClick(e)
        End Sub
    End Class
    si vous voulez utilser Rectangle Personnaliser, il faudra changer ce 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
     
    ...etc
    If (e.ItemState And ListViewItemStates.Selected) <> 0 Then
                    Using Brush As New SolidBrush(Color.YellowGreen)
                        e.Graphics.FillRectangle(Brush, New Rectangle(e.Bounds.X + 23, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height))
                    End Using
                End If
    ..etc
    If state = CheckBoxState.UncheckedNormal Then
                    e.Graphics.FillRectangle(New SolidBrush(Color.Red), New Rectangle(rect.X, rect.Y + 2, rect.Width, rect.Height))
                    e.Graphics.DrawString("X", New Font("Verdana", 12, FontStyle.Bold), New SolidBrush(Color.White), New Rectangle(e.Bounds.X + 2, e.Bounds.Y + 2, e.Bounds.Width, e.Bounds.Height))
                ElseIf state = CheckBoxState.CheckedNormal Then
                    e.Graphics.FillRectangle(New SolidBrush(Color.Green), New Rectangle(rect.X, rect.Y + 2, rect.Width, rect.Height))
                    rect.Inflate(-4, -4)
                    e.Graphics.SmoothingMode = SmoothingMode.AntiAlias
                    e.Graphics.DrawLines(New Pen(New SolidBrush(Color.White), 2), New Point() {New Point(rect.Left, rect.Bottom - rect.Right / 2), New Point(rect.Left + rect.Width / 3, rect.Bottom - 2), New Point(rect.Right, rect.Top)})
                    e.Graphics.SmoothingMode = SmoothingMode.Default
                    rect.Inflate(+4, +4)
                End If
                Dim width As Integer = TextRenderer.MeasureText(Space(2), e.SubItem.Font).Width
                TextRenderer.DrawText(e.Graphics, e.SubItem.Text, e.SubItem.Font, Rectangle.Inflate(e.Bounds, -width, 0), e.Item.ForeColor, TextFormatFlags.LeftAndRightPadding)
            Else
                TextRenderer.DrawText(e.Graphics, e.SubItem.Text, e.SubItem.Font, e.Bounds, e.Item.ForeColor, TextFormatFlags.HorizontalCenter)
            End If
        End Sub
    Voici comment j'ai résolu le probléme dans l'ecriture dans listview1. cordialement,

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

Discussions similaires

  1. Fixer un largeur dans <p:column>
    Par maserati dans le forum JSF
    Réponses: 9
    Dernier message: 16/05/2012, 09h53
  2. Update des data dans une column varchar2(3 byte)
    Par Kagukuk dans le forum SQL
    Réponses: 4
    Dernier message: 15/11/2011, 15h45
  3. Problème HREF dans display column
    Par endbegins dans le forum Développement Web en Java
    Réponses: 4
    Dernier message: 09/04/2011, 13h37
  4. Ajouter un alias dans une column
    Par persia dans le forum Requêtes
    Réponses: 3
    Dernier message: 29/10/2010, 08h19
  5. Images pas cache dans une column de DataGrid
    Par Gaaaga dans le forum Flex
    Réponses: 0
    Dernier message: 27/05/2008, 10h29

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