Bonjour
Comment fait on pour enlever la bordure d'une progressBar ?
Merci
Version imprimable
Bonjour
Comment fait on pour enlever la bordure d'une progressBar ?
Merci
en surchargeant le OnPaint()
C'est vraiment facile de se faire une progressBar customisée cf.
Code:
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 public partial class BasicProgressBar : UserControl { public BasicProgressBar() { InitializeComponent(); FillBrush = new SolidBrush(BarColor); BackBrush = new SolidBrush(BackColor); } public override Color BackColor { get { return base.BackColor; } set { base.BackColor = value; BackBrush = new SolidBrush(value); } } int maximum = 0; int value = 0; public virtual int Maximum { get { return maximum; } set { maximum = value; Invalidate(); } } public virtual int Value { get { return value; } set { this.value = value; Invalidate(); } } Color barColor = Color.White; protected virtual Brush FillBrush { get; set; } protected virtual Brush BackBrush { get; set; } public virtual Color BarColor { get { return barColor; } set { barColor = value; FillBrush = new SolidBrush(barColor); Invalidate(); } } protected override void OnPaint(PaintEventArgs e) { if (Width > 1 && Height > 1) { if (Value >= 0 && Maximum > 0) { double percent = ((double)Value) / ((double)Maximum); int desiredWidth = (int)(Width * percent); e.Graphics.FillRectangle(FillBrush, 0, 0, desiredWidth, Height); if (desiredWidth < Width) { e.Graphics.FillRectangle(BackBrush, desiredWidth, 0, (Width - desiredWidth), Height); } } } base.OnPaint(e); } }