|
Trouver une ressource
Vous ne trouvez pas de réponse à votre problème ? Alors posez la question dans le forum. Souvenez-vous qu'il n'y a jamais de question bête, mais rester dans l'ignorance parce que l'on n'ose pas poser une question, ça c'est une erreur !
BARRE DE PROGRESSION ANIMÉE À LA APPLE MACINTOSH
Information sur la source
Description
Salut; Il s'agit d'une petite bar de progression très belle que j'ai crée en vue d'un projet surlequel je travaille. Elle hérite de la classe System.Windows.Forms.Control et voici ces principaux paramètres: - Value : valeur courante de la progression. (Entre 0 et Maximum) - Maximum : valeur maximale qu'on ne peut pas dépasser - BackgroundImage : Image d'arrière plan - Image : Image de l'avant-plan, elle est necessaire pour l'affichage - Animate : si Animate == true, alors l'image d'avant-plan donne l'impression de reculer alors que la valeur ne change pas ou qu'elle augmente (à essayer, c'est ce qui fait d'ailleurs la force de cette progressBar) - Step et TimerSpeed : ces deux valeurs influence la vitesse du "défilement arrière" (voir Animate) si Animate == true biensur - BorderColor : couleur de la bordure Le code source de ce contrôle est commenté et facile à comprendre. Il est développé sous MS VS2003 avec .Net 1.1 (eh oui, il faut le spécifier maintenant :)
Source
- using System;
- using System.Collections;
- using System.ComponentModel;
- using System.Drawing;
- using System.Drawing.Drawing2D;
- using System.Data;
- using System.Windows.Forms;
-
- namespace advancedDesign
- {
- public class MacProgressBar : System.Windows.Forms.Control
- {
- #region variables graphiques
- //la hauteur de notre progressbar doit être égal à 16px en tout temps
- #region MacProgressBar Size
- protected override void OnSizeChanged(EventArgs e)
- {
- this.Height = 16;
- //on en profite pour metter a jour notre rectangle client
- myClientRectangle = this.ClientRectangle;
- myClientRectangle.Width--;
- myClientRectangle.Height--;
- base.OnSizeChanged (e);
- }
-
- #endregion
- //la couleur de la bordure (noir par défaut)
- private Color borderColor = Color.Black;
- public Color BorderColor {get{return borderColor;}set{borderColor=value; this.Invalidate();}}
- //bitmap contenant l'image de front de la progressBar
- private Bitmap bmp = null;
- public Bitmap Image {get {return bmp;}set{bmp = value; if(animate==true && timer.Enabled == false) StartAnimation();}}
- //tableau qui contient le rectangle client qui déborde pas d'un pixel lors
- //de l'affichage
- private Rectangle myClientRectangle;
- //offset va servir a annimé l'image de la progressbar (alias bmp)
- private int offset = 0;
- private int step = 1;
- public int Step {get{return step;}set{if(value>0) step=value;}}
- private int timerSpeed = 100; //vitesse du timer en milliseconde
- public int TimerSpeed {get{return timerSpeed;}set{if(value>0) {timerSpeed = value; timer.Interval = value;}}}
- //si annimate == true, on voit la progressBar bouger "à reculant"
- private bool animate = false;
- public bool Animate
- {
- get{return animate;}
- set{this.animate = value; if(value) StartAnimation(); else StopAnimation();}
- }
-
-
- #endregion
-
- //valeur de la progression
- private int val = 0;
- public int Value {get{return val;}set{if(value>max) val=max; else val=value; this.Invalidate();}}
- //valeur maximale, value ne doit pas dépasser max
- private int max = 100;
- private System.Windows.Forms.Timer timer;
- private System.ComponentModel.IContainer components;
-
- public int Maximum {get{return max;}set{if(value<val) max=val;else max=value; this.Invalidate();}}
-
- public MacProgressBar()
- {
- this.SetStyle(ControlStyles.UserPaint|ControlStyles.DoubleBuffer|ControlStyles.ResizeRedraw, true);
- InitializeComponent();
- }
-
- #region dispose
- protected override void Dispose( bool disposing )
- {
- if( disposing )
- {
- if( components != null )
- components.Dispose();
- }
- base.Dispose( disposing );
- }
- #endregion
-
- #region Component Designer generated code
- /// <summary>
- /// Required method for Designer support - do not modify
- /// the contents of this method with the code editor.
- /// </summary>
- private void InitializeComponent()
- {
- this.components = new System.ComponentModel.Container();
- this.timer = new System.Windows.Forms.Timer(this.components);
- //
- // timer
- //
- this.timer.Tick += new System.EventHandler(this.timer_Tick);
-
- }
- #endregion
-
- protected override void OnPaint(PaintEventArgs pe)
- {
- //on affiche pas la progression s'il n'y a pas d'images
- if(bmp!=null)
- {
- using(TextureBrush textBrush = new TextureBrush(bmp))
- {
- //translation pour l'effet du défilement arrière
- pe.Graphics.TranslateTransform(-offset,0);
- pe.Graphics.FillRectangle(textBrush, 0, 1, ((float)val/max)*(this.Width-2)+offset, 14);
- }
- }
- //on annule l'effet de la translation
- pe.Graphics.Transform = new Matrix();
- //on affiche la bordure avec la couleur adéquate
- pe.Graphics.DrawRectangle(new Pen(borderColor), this.myClientRectangle);
- base.OnPaint(pe);
- }
-
- private void StartAnimation()
- {
- if(bmp!=null)
- {
- timer.Start();
- }
- }
- private void StopAnimation()
- {
- timer.Stop();
- }
-
- private void timer_Tick(object sender, System.EventArgs e)
- {
- this.offset+=step;
- this.Invalidate();
- if(offset==bmp.Width) offset = 0;
- }
- }
- }
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Data;
using System.Windows.Forms;
namespace advancedDesign
{
public class MacProgressBar : System.Windows.Forms.Control
{
#region variables graphiques
//la hauteur de notre progressbar doit être égal à 16px en tout temps
#region MacProgressBar Size
protected override void OnSizeChanged(EventArgs e)
{
this.Height = 16;
//on en profite pour metter a jour notre rectangle client
myClientRectangle = this.ClientRectangle;
myClientRectangle.Width--;
myClientRectangle.Height--;
base.OnSizeChanged (e);
}
#endregion
//la couleur de la bordure (noir par défaut)
private Color borderColor = Color.Black;
public Color BorderColor {get{return borderColor;}set{borderColor=value; this.Invalidate();}}
//bitmap contenant l'image de front de la progressBar
private Bitmap bmp = null;
public Bitmap Image {get {return bmp;}set{bmp = value; if(animate==true && timer.Enabled == false) StartAnimation();}}
//tableau qui contient le rectangle client qui déborde pas d'un pixel lors
//de l'affichage
private Rectangle myClientRectangle;
//offset va servir a annimé l'image de la progressbar (alias bmp)
private int offset = 0;
private int step = 1;
public int Step {get{return step;}set{if(value>0) step=value;}}
private int timerSpeed = 100; //vitesse du timer en milliseconde
public int TimerSpeed {get{return timerSpeed;}set{if(value>0) {timerSpeed = value; timer.Interval = value;}}}
//si annimate == true, on voit la progressBar bouger "à reculant"
private bool animate = false;
public bool Animate
{
get{return animate;}
set{this.animate = value; if(value) StartAnimation(); else StopAnimation();}
}
#endregion
//valeur de la progression
private int val = 0;
public int Value {get{return val;}set{if(value>max) val=max; else val=value; this.Invalidate();}}
//valeur maximale, value ne doit pas dépasser max
private int max = 100;
private System.Windows.Forms.Timer timer;
private System.ComponentModel.IContainer components;
public int Maximum {get{return max;}set{if(value<val) max=val;else max=value; this.Invalidate();}}
public MacProgressBar()
{
this.SetStyle(ControlStyles.UserPaint|ControlStyles.DoubleBuffer|ControlStyles.ResizeRedraw, true);
InitializeComponent();
}
#region dispose
protected override void Dispose( bool disposing )
{
if( disposing )
{
if( components != null )
components.Dispose();
}
base.Dispose( disposing );
}
#endregion
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.timer = new System.Windows.Forms.Timer(this.components);
//
// timer
//
this.timer.Tick += new System.EventHandler(this.timer_Tick);
}
#endregion
protected override void OnPaint(PaintEventArgs pe)
{
//on affiche pas la progression s'il n'y a pas d'images
if(bmp!=null)
{
using(TextureBrush textBrush = new TextureBrush(bmp))
{
//translation pour l'effet du défilement arrière
pe.Graphics.TranslateTransform(-offset,0);
pe.Graphics.FillRectangle(textBrush, 0, 1, ((float)val/max)*(this.Width-2)+offset, 14);
}
}
//on annule l'effet de la translation
pe.Graphics.Transform = new Matrix();
//on affiche la bordure avec la couleur adéquate
pe.Graphics.DrawRectangle(new Pen(borderColor), this.myClientRectangle);
base.OnPaint(pe);
}
private void StartAnimation()
{
if(bmp!=null)
{
timer.Start();
}
}
private void StopAnimation()
{
timer.Stop();
}
private void timer_Tick(object sender, System.EventArgs e)
{
this.offset+=step;
this.Invalidate();
if(offset==bmp.Width) offset = 0;
}
}
}
Conclusion
Si vous avez des commentaires, n'hésitez pas à me les dire merci et à la prochaine
Sources du même auteur
Sources de la même categorie
Sources en rapport avec celle ci
Commentaires et avis
Discussions en rapport avec ce code source dans le forum
User et Custom CONTROL [ par adir ]
est ce qu'il y a des gens qui ont des informations sur la creation et l'utilisation de USERCONTROL et CUSTOMCONTROLj'ai un peu du mal à m'en servirj'a
DataBind Silverlight2 C# [ par Link214 ]
Bonjours a tous, je rencontre actuellement des souci avec un databind sur mon custom control, je fait mon data bind comme preconiser dans la msdn : da
MDI Form parent avec control bouton [ par seb123 ]
Bonjour,Je voudrai placer un bouton sur une MDI form parent mais quand j'ouvre une MDI form child le bouton apparait en premier plan devant la MDI chi
Remplissage controle [ par juanfs ]
Bonjour,Est il possible en c# de remplir un control directement avec un objet, c'est a dire gérer le remplissage avec un labelProvider(comme en java)
Probleme en Dundas [ par asma86 ]
Je developpe une application en utilisant le control "Dundas Chart Entreprise" pour afficher un graphe.Aprés avoir ecrir les instructions pour se conn
barre de progression [ par verbeyst ]
Bonjour,J'utilise dans mon application une barre de progression.Je voudrais qu'elle apparaisse dans le "bas" de mon formulaire window un peu comme on
grid control +binding Source [ par issamglad ]
bonjour,dans notre application on a un grid control qui a comme source de donnees une binding source , on aimerais ajouter un champs dans notre grid c
Connaitre le control qui a le focus [ par Ethan ]
Bonjour a tous,J'utilise une form qui contient forcement des controls (datagrid, tabcontrol, ...). Chaque tabcontrol contient eux aussi des controles.
UserControl c'est quoi ? [ par olibara ]
BonjourMa question est sans doute idote pour la pluspart d'entre vous mais bon quand on ne sait pas on cherche a savoir !Donc je ne sais pas vraiment
Obtenir le type d'un Control [ par LordOfTheShadow ]
Bonjour,Je voudrai savoir savoir comment on peut récupérer le type (ex: bouton, label, etc..) d'un Control. Si je pourrai avoir un exemple de code ça
|
Téléchargements
Logiciels à télécharger sur le même thème :
Comparez les prix Nouvelle version
|