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

Windows Forms Discussion :

Modifier le design de la progress bar


Sujet :

Windows Forms

  1. #1
    Nouveau candidat au Club
    Homme Profil pro
    Etudiant
    Inscrit en
    Novembre 2016
    Messages
    1
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 30
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Etudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Novembre 2016
    Messages : 1
    Par défaut Modifier le design de la progress bar
    Bonjour à tous !

    Alors voilà,

    Voici la progress bar, qu'il me faudrait :

    Nom : Capture.JPG
Affichages : 571
Taille : 29,6 Ko

    Cependant j'ai par defaut celle la :

    Nom : Capture.JPG
Affichages : 509
Taille : 28,6 Ko

    Pouvez vous me dire comment peux t'on modifier le design de cette barre ? Afin d'avoir la même qu'a la première image ?

    Merci

  2. #2
    Membre Expert Avatar de jopopmk
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Mars 2011
    Messages
    1 856
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mars 2011
    Messages : 1 856
    Par défaut
    Salut,

    je crois pas que ce soit faisable, du moins j'ai pas trouvé d'option pour un affichage "flat".
    Du coup il te reste que la solution de faire ta propre ProgressBar (qui peut hériter de l'existante).

    Bon dev.

  3. #3
    Membre extrêmement actif
    Inscrit en
    Avril 2008
    Messages
    2 573
    Détails du profil
    Informations personnelles :
    Âge : 65

    Informations forums :
    Inscription : Avril 2008
    Messages : 2 573
    Par défaut
    bonjour

    Le voilà ,c'est gratis,tiré de la rubrique intitulé "How to create a smooth progress bar in Visual C# .NET" de la MSDN Library fr ....c'est un usercontrol:

    code .cs du usercontrol SmoothProgressBar:
    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
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
     
     
    using System;
    using System.Drawing;
    using System.Windows.Forms;
     
    namespace WinSmoothProgressBar
    {
        public partial class SmoothProgressBar : UserControl
        {
            int min = 0;	// Minimum value for progress range
            int max = 100;	// Maximum value for progress range
            int val = 0;		// Current progress
            Color BarColor = Color.Blue;		// Color of progress meter
     
            public SmoothProgressBar()
            {
                InitializeComponent();
            }
     
            protected override void OnResize(EventArgs e)
            {
                // Invalidate the control to get a repaint.
                this.Invalidate();
            }
     
            protected override void OnPaint(PaintEventArgs e)
            {
                Graphics g = e.Graphics;
                SolidBrush brush = new SolidBrush(BarColor);
                float percent = (float)(val - min) / (float)(max - min);
                Rectangle rect = this.ClientRectangle;
     
                // Calculate area for drawing the progress.
                rect.Width = (int)((float)rect.Width * percent);
     
                // Draw the progress meter.
                g.FillRectangle(brush, rect);
     
                // Draw a three-dimensional border around the control.
                Draw3DBorder(g);
     
                // Clean up.
                brush.Dispose();
                g.Dispose();
            }
     
            public int Minimum
            {
                get
                {
                    return min;
                }
     
                set
                {
                    // Prevent a negative value.
                    if (value < 0)
                    {
                        min = 0;
                    }
     
                    // Make sure that the minimum value is never set higher than the maximum value.
                    if (value > max)
                    {
                        min = value;
                        min = value;
                    }
     
                    // Ensure value is still in range
                    if (val < min)
                    {
                        val = min;
                    }
     
                    // Invalidate the control to get a repaint.
                    this.Invalidate();
                }
            }
     
            public int Maximum
            {
                get
                {
                    return max;
                }
     
                set
                {
                    // Make sure that the maximum value is never set lower than the minimum value.
                    if (value < min)
                    {
                        min = value;
                    }
     
                    max = value;
     
                    // Make sure that value is still in range.
                    if (val > max)
                    {
                        val = max;
                    }
     
                    // Invalidate the control to get a repaint.
                    this.Invalidate();
                }
            }
     
            public int Value
            {
                get
                {
                    return val;
                }
     
                set
                {
                    int oldValue = val;
     
                    // Make sure that the value does not stray outside the valid range.
                    if (value < min)
                    {
                        val = min;
                    }
                    else if (value > max)
                    {
                        val = max;
                    }
                    else
                    {
                        val = value;
                    }
     
                    // Invalidate only the changed area.
                    float percent;
     
                    Rectangle newValueRect = this.ClientRectangle;
                    Rectangle oldValueRect = this.ClientRectangle;
     
                    // Use a new value to calculate the rectangle for progress.
                    percent = (float)(val - min) / (float)(max - min);
                    newValueRect.Width = (int)((float)newValueRect.Width * percent);
     
                    // Use an old value to calculate the rectangle for progress.
                    percent = (float)(oldValue - min) / (float)(max - min);
                    oldValueRect.Width = (int)((float)oldValueRect.Width * percent);
     
                    Rectangle updateRect = new Rectangle();
     
                    // Find only the part of the screen that must be updated.
                    if (newValueRect.Width > oldValueRect.Width)
                    {
                        updateRect.X = oldValueRect.Size.Width;
                        updateRect.Width = newValueRect.Width - oldValueRect.Width;
                    }
                    else
                    {
                        updateRect.X = newValueRect.Size.Width;
                        updateRect.Width = oldValueRect.Width - newValueRect.Width;
                    }
     
                    updateRect.Height = this.Height;
     
                    // Invalidate the intersection region only.
                    this.Invalidate(updateRect);
                }
            }
     
            public Color ProgressBarColor
            {
                get
                {
                    return BarColor;
                }
     
                set
                {
                    BarColor = value;
     
                    // Invalidate the control to get a repaint.
                    this.Invalidate();
                }
            }
     
            private void Draw3DBorder(Graphics g)
            {
                int PenWidth = (int)Pens.White.Width;
     
                g.DrawLine(Pens.DarkGray,
                    new Point(this.ClientRectangle.Left, this.ClientRectangle.Top),
                    new Point(this.ClientRectangle.Width - PenWidth, this.ClientRectangle.Top));
                g.DrawLine(Pens.DarkGray,
                    new Point(this.ClientRectangle.Left, this.ClientRectangle.Top),
                    new Point(this.ClientRectangle.Left, this.ClientRectangle.Height - PenWidth));
                g.DrawLine(Pens.White,
                    new Point(this.ClientRectangle.Left, this.ClientRectangle.Height - PenWidth),
                    new Point(this.ClientRectangle.Width - PenWidth, this.ClientRectangle.Height - PenWidth));
                g.DrawLine(Pens.White,
                    new Point(this.ClientRectangle.Width - PenWidth, this.ClientRectangle.Top),
                    new Point(this.ClientRectangle.Width - PenWidth, this.ClientRectangle.Height - PenWidth));
            } 
     
        }
    }
    code .cs du form de test :
    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
     
     
    namespace WinSmoothProgreesBar
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
     
            private void button1_Click(object sender, EventArgs e)
            {
                this.smoothProgressBar1.Value = 0;
     
                this.timer1.Interval = 1;
                this.timer1.Enabled = true; 
     
            }
     
            private void timer1_Tick(object sender, EventArgs e)
            {
                if (this.smoothProgressBar1.Value <= 100)
                {
                    this.smoothProgressBar1.Value++;
                }
                else
                {
                    this.timer1.Enabled = false;
                } 
     
     
            }
     
     
        }
    }
    bon code....

Discussions similaires

  1. Réponses: 3
    Dernier message: 26/06/2009, 09h30
  2. [ATL] Petite question sur les progress bar
    Par MrMaze dans le forum MFC
    Réponses: 1
    Dernier message: 06/05/2005, 09h40
  3. [MFC]Changer la couleur d'un progress bar
    Par Deedier dans le forum MFC
    Réponses: 1
    Dernier message: 21/04/2005, 18h39
  4. [VB.NET] Mise en place d'une progress bar
    Par Hoegaarden dans le forum Windows Forms
    Réponses: 14
    Dernier message: 19/10/2004, 09h23
  5. Progress bar au boot
    Par saibe dans le forum Administration système
    Réponses: 2
    Dernier message: 18/08/2003, 10h01

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