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 :

probleme multiple color


Sujet :

VB.NET

  1. #1
    Membre actif
    Homme Profil pro
    Étudiant
    Inscrit en
    Janvier 2018
    Messages
    293
    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 : 293
    Points : 245
    Points
    245
    Par défaut probleme multiple color
    Bonjour, j'ai petit problème espace sur un label avec datetime entre 05:46 et data aujourd'hui.(voir image)

    voici en image :
    Nom : color.png
Affichages : 83
Taille : 4,2 Ko

    dans Timer_Tick :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
     GetCenterLabel(Label2, TimeZoneInfo.ConvertTimeToUtc(UTCTime, UTC).ToString("HH:mm dd/MM/yyyy"), 85, FontStyle.Bold)
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    Private Sub GetCenterLabel(lb As Label, info As String, FondSize As Integer, _FondStyle As FontStyle)
            lb.Text = info
            lb.Left = (Me.Width \ 2) - (lb.Width \ 2)
            lb.Top = (Me.Height \ 2) - (lb.Height \ 2)
            lb.Font = GetFont(My.Resources.DS_DIGIB, FondSize, _FondStyle)
            lb.TextAlign = ContentAlignment.MiddleCenter
            lb.ForeColor = Me.BackColor
        End Sub
    dans Label2_Paint :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    DrawColorText(CType(sender, Label), Label2.Text, e, 85, FontStyle.Bold)
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    Private Sub DrawColorText(LBL As Label, _info As String, e As PaintEventArgs, FondSize As Integer, _FondStyle As FontStyle)
            Dim MyChar As String() = {":", " ", "/", "/"}
            Dim MyFont As Font = GetFont(My.Resources.DS_DIGIB, FondSize, _FondStyle)
            Dim jour As String() = _info.Split(New Char() {":", " ", "/"}, StringSplitOptions.RemoveEmptyEntries)
            Dim x As Integer = 0
            For i As Integer = 0 To jour.Length - 1
                e.Graphics.DrawString(jour(i), MyFont, New SolidBrush(_MyColor(i)), x, 0)
                x += (e.Graphics.MeasureString(jour(i), MyFont)).Width - (LBL.Width / 22)
                If i < (jour.Length - 1) Then
                    e.Graphics.DrawString(MyChar(i), MyFont, New SolidBrush(Me.ForeColor), x, 0)
                    x += (e.Graphics.MeasureString(MyChar(i), MyFont)).Width - (LBL.Width / 22)
                End If
            Next
        End Sub
    pouvez-vous m'aider à avoir l'espace entre l'heure et la date ? merci d'avance

  2. #2
    Membre expérimenté
    Profil pro
    Inscrit en
    Septembre 2010
    Messages
    1 198
    Détails du profil
    Informations personnelles :
    Âge : 45
    Localisation : France

    Informations forums :
    Inscription : Septembre 2010
    Messages : 1 198
    Points : 1 748
    Points
    1 748
    Par défaut
    Est-ce que l'espace est défini dans ta Font ? (si tu fais pas la coloration, est-ce l'espace est visible?)

    Si l'espace n'est pas géré, il va falloir le traiter à part (utiliser une autre font de même taille par exemple)

  3. #3
    Membre éprouvé
    Profil pro
    Inscrit en
    Octobre 2006
    Messages
    666
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2006
    Messages : 666
    Points : 1 163
    Points
    1 163
    Par défaut
    Bonjour,
    avez vous testé : TextRenderer.MeasureText à la place de e.Graphics.MeasureString ?

  4. #4
    Membre actif
    Homme Profil pro
    Étudiant
    Inscrit en
    Janvier 2018
    Messages
    293
    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 : 293
    Points : 245
    Points
    245
    Par défaut
    Bonjour a tous, merci de votre réponse car j'ai trouver la solution à mon problème.

    Nom : Capture d’écran 2024-06-25 151737.png
Affichages : 37
Taille : 7,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
    Private _MyColor As Color() = {Color.Blue, Color.Green, Color.DodgerBlue, Color.Red, Color.Yellow}
     
    Private Sub DrawColorText(g As Graphics, r As Rectangle, _info As String, FondSize As Integer, _FondStyle As FontStyle)
            Dim MyFont As Font = GetFont(My.Resources.DS_DIGIB, FondSize, _FondStyle)
            Dim jour As String() = _info.Split(New Char() {":", " ", "/"}, StringSplitOptions.RemoveEmptyEntries)
            TextRenderer.DrawText(g, _info, MyFont, New Point(0, 0), Me.ForeColor)
            If (Me.Text.Length <= 0) Then Return
            For i As Integer = 0 To jour.Length - 1
                Dim keyWidth As Integer = TextRenderer.MeasureText(jour(i), MyFont).Width
                Dim IndexOffset As Integer = _info.IndexOf(jour(i))
                While IndexOffset >= 0
                    Dim StrFront As String = Text.Substring(0, IndexOffset)
                    If StrFront.Length > 0 Then
                        Dim strWidth As Integer = TextRenderer.MeasureText(StrFront & jour(i), MyFont).Width
                        TextRenderer.DrawText(g, jour(i), MyFont, New Point((strWidth - keyWidth), 0), _MyColor(i))
                    Else
                        TextRenderer.DrawText(g, jour(i), MyFont, New Point(0, 0), _MyColor(i))
                    End If
                    IndexOffset += jour(i).Length
                    If IndexOffset >= _info.Length Then Exit While
                    Dim StrBehind As String = _info.Substring(IndexOffset)
                    If StrBehind.Length <= 0 Then Exit While
                    Dim index2 As Integer = StrBehind.IndexOf(jour(i))
                    If index2 < 0 Then Exit While
                    IndexOffset += index2
                End While
            Next

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

Discussions similaires

  1. [Math]problème multiplication double
    Par xso dans le forum Général Java
    Réponses: 29
    Dernier message: 04/12/2010, 15h04
  2. Problemes multiples avec "case à cocher"
    Par guidzit dans le forum Access
    Réponses: 13
    Dernier message: 21/09/2006, 14h46
  3. Réponses: 4
    Dernier message: 28/08/2006, 17h11
  4. Réponses: 7
    Dernier message: 26/01/2006, 12h20

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