Paradise GTP
Premium
Vous devez être inscrit pour voir les liens ! Inscrivez-vous ou connectez-vous ici.
[VB.NET] Créez vos propres items. [Épisode 1 - ProgressBar arrondie / ProgressBar]
[tabs]
[tab=Informations concernant ce tutoriel]• Temps de lecture : 15 minutes.
• Temps de rédaction : 03 heures.
• Difficulté : ★★★★
• Matériel requis : Ordinateur sous Windows XP/Vista/7/8/8.1, Visual Studio.
• Tutoriel proposé par la GTP, écris par Boosterz GTP.
[/tab]
[/tabs]

Vous devez être inscrit pour voir les liens ! Inscrivez-vous ou connectez-vous ici.
ProgressBar Arrondie
Donc durant ce tutoriel je vais vous apprendre à créer une ProgressBar arrondie en VB.NET.
Voila à quoi elle ressemblera :

( L'image bug car le .gif ne suis pas, je vous rassure vous cela fait % par %. )
Donc vous allez commencer par ajouté une classe à votre logiciel.
Vous l'appelez comme vous voulez cela a peu d'importance.
On commence par importer :
Code:
Imports System.Drawing.Drawing2D
Imports System.Drawing
Imports System.Windows.Forms
Imports System.Drawing.Text
Imports System.ComponentModel
Code:
Enum MouseState As Byte
Normal = 0
Hovered = 1
Pushed = 2
Disabled = 3
End Enum
Code:
Module Draw

Ensuite dans ce module on va mettre plusieurs sub, fonction.
On commence par le sub drawcorners :
Code:
Public Sub drawcorners(ByVal B As Bitmap, ByVal c As Color)
B.SetPixel(0, 0, c)
B.SetPixel(1, 0, c)
B.SetPixel(0, 1, c)
B.SetPixel(B.Width - 1, 0, c)
B.SetPixel(B.Width - 1, 1, c)
B.SetPixel(B.Width - 2, 0, c)
B.SetPixel(B.Width - 1, B.Height - 1, c)
B.SetPixel(B.Width - 1, B.Height - 2, c)
B.SetPixel(B.Width - 2, B.Height - 1, c)
B.SetPixel(0, B.Height - 1, c)
B.SetPixel(0, B.Height - 2, c)
B.SetPixel(1, B.Height - 1, c)
End Sub

C'est aussi simple que sa, ensuite deux fonctions :
Code:
Public Function GetBrush(ByVal c As Color) As SolidBrush
Return New SolidBrush(c)
End Function
Public Function GetPen(ByVal c As Color) As Pen
Return New Pen(New SolidBrush(c))
End Function

Et encore une autre fonction
Code:
Function NoiseBrush(Colors As Color()) As TextureBrush
Dim B As New Bitmap(128, 128)
Dim R As New Random(128)
For X As Integer = 0 To B.Width - 1
For Y As Integer = 0 To B.Height - 1
B.SetPixel(X, Y, Colors(R.Next(Colors.Length)))
Next
Next
Dim T As New TextureBrush(B)
B.Dispose()
Return T
End Function
Code:
Public Sub InnerGlow(ByVal G As Graphics, ByVal Rectangle As Rectangle, ByVal Colors As Color())
Dim SubtractTwo As Integer = 1
Dim AddOne As Integer = 0
For Each c In Colors
G.DrawRectangle(New Pen(New SolidBrush(Color.FromArgb(c.R, c.B, c.G))), Rectangle.X + AddOne, Rectangle.Y + AddOne, Rectangle.Width - SubtractTwo, Rectangle.Height - SubtractTwo)
SubtractTwo += 2
AddOne += 1
Next
End Sub
Public Sub InnerGlowRounded(ByVal G As Graphics, ByVal Rectangle As Rectangle, ByVal Degree As Integer, ByVal Colors As Color())
Dim SubtractTwo As Integer = 1
Dim AddOne As Integer = 0
For Each c In Colors
G.DrawPath(New Pen(New SolidBrush(Color.FromArgb(c.R, c.B, c.G))), Draw.RoundRect(Rectangle.X + AddOne, Rectangle.Y + AddOne, Rectangle.Width - SubtractTwo, Rectangle.Height - SubtractTwo, Degree))
SubtractTwo += 2
AddOne += 1
Next
End Sub
Code:
Function ToBrush(ByVal A As Integer, ByVal R As Integer, ByVal G As Integer, ByVal B As Integer) As Brush
Return New SolidBrush(Color.FromArgb(A, R, G, B))
End Function
Function ToBrush(ByVal R As Integer, ByVal G As Integer, ByVal B As Integer) As Brush
Return New SolidBrush(Color.FromArgb(R, G, B))
End Function
Function ToBrush(ByVal A As Integer, ByVal C As Color) As Brush
Return New SolidBrush(Color.FromArgb(A, C))
End Function
Function ToBrush(ByVal Pen As Pen) As Brush
Return New SolidBrush(Pen.Color)
End Function
Function ToBrush(ByVal Color As Color) As Brush
Return New SolidBrush(Color)
End Function
Function ToPen(ByVal A As Integer, ByVal R As Integer, ByVal G As Integer, ByVal B As Integer) As Pen
Return New Pen(New SolidBrush(Color.FromArgb(A, R, G, B)))
End Function
Function ToPen(ByVal R As Integer, ByVal G As Integer, ByVal B As Integer) As Pen
Return New Pen(New SolidBrush(Color.FromArgb(R, G, B)))
End Function
Function ToPen(ByVal A As Integer, ByVal C As Color) As Pen
Return New Pen(New SolidBrush(Color.FromArgb(A, C)))
End Function
Function ToPen(ByVal Brush As SolidBrush) As Pen
Return New Pen(Brush)
End Function
Function ToPen(ByVal Color As Color) As Pen
Return New Pen(New SolidBrush(Color))
End Function
Public Function RoundRect(ByVal Rectangle As Rectangle, ByVal Curve As Integer) As GraphicsPath
Dim P As GraphicsPath = New GraphicsPath()
Dim ArcRectangleWidth As Integer = Curve * 2
P.FillMode = FillMode.Winding
P.AddArc(New Rectangle(Rectangle.X, Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), -180, 90)
P.AddArc(New Rectangle(Rectangle.Width - ArcRectangleWidth + Rectangle.X, Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), -90, 90)
P.AddArc(New Rectangle(Rectangle.Width - ArcRectangleWidth + Rectangle.X, Rectangle.Height - ArcRectangleWidth + Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), 0, 90)
P.AddArc(New Rectangle(Rectangle.X, Rectangle.Height - ArcRectangleWidth + Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), 90, 90)
P.AddLine(New Point(Rectangle.X, Rectangle.Height - ArcRectangleWidth + Rectangle.Y), New Point(Rectangle.X, Curve + Rectangle.Y))
P.CloseAllFigures()
Return P
End Function
Public Function RoundRect(ByVal X As Integer, ByVal Y As Integer, ByVal Width As Integer, ByVal Height As Integer, ByVal Curve As Integer) As GraphicsPath
Dim Rectangle As Rectangle = New Rectangle(X, Y, Width, Height)
Dim P As GraphicsPath = New GraphicsPath()
P.FillMode = FillMode.Winding
Dim ArcRectangleWidth As Integer = Curve * 2
P.AddArc(New Rectangle(Rectangle.X, Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), -180, 90)
P.AddArc(New Rectangle(Rectangle.Width - ArcRectangleWidth + Rectangle.X, Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), -90, 90)
P.AddArc(New Rectangle(Rectangle.Width - ArcRectangleWidth + Rectangle.X, Rectangle.Height - ArcRectangleWidth + Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), 0, 90)
P.AddArc(New Rectangle(Rectangle.X, Rectangle.Height - ArcRectangleWidth + Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), 90, 90)
P.AddLine(New Point(Rectangle.X, Rectangle.Height - ArcRectangleWidth + Rectangle.Y), New Point(Rectangle.X, Curve + Rectangle.Y))
P.CloseAllFigures()
Return P
End Function
Public Sub DrawDropShadow(G As Graphics, Color As Color, pth As GraphicsPath, size As Integer, Optional Angle As Single = 120, Optional Distance As Single = 0, Optional Opacity As Single = 1, Optional Spread As Single = 2)
If Angle > 360 Then Angle = 360 * (Angle / 360 - Math.Floor(Angle / 360))
If Angle < 0 Then Angle = 360 * (Angle / 360 - Math.Floor(Angle / 360))
If Distance < 0 Then Throw New Exception("The distance have to be => 0")
If Opacity < 0 Or Opacity > 1 Then Throw New Exception("The opacity have to be between 1 and 0")
Dim pthCopy As GraphicsPath = pth.Clone
size *= 2
Dim xi As Double = Math.Cos((Math.PI / 180) * (Angle - 90)) * Distance
Dim yi As Double = Math.Sin((Math.PI / 180) * (Angle - 90)) * Distance
If Distance > 0 Then pthCopy.Transform(New Matrix(1, 0, 0, 1, xi, yi))
Dim OldClip As Region = G.Clip
Dim NewClip As GraphicsPath = pth.Clone
Dim b = NewClip.GetBounds
NewClip.Transform(New Matrix((b.Width - 1) / b.Width, 0, 0, (b.Height - 1) / b.Height, 0.5, 0.5))
NewClip.AddRectangle(New RectangleF((b.X - size) * 2, (b.Y - size) * 2, (b.Width + size) * 2, (b.Height + size) * 2))
G.SetClip(NewClip)
For i = 0 To size
b = pthCopy.GetBounds
Using m As New Matrix((b.Width + 1) / b.Width, 0, 0, (b.Height + 1) / b.Height, -0.5, -0.5)
Using br As New SolidBrush(Color.FromArgb((((255 - Math.Pow(i / size, 1 + Spread) * 255) * Opacity) / size), Color))
pthCopy.Transform(m)
G.FillPath(br, pthCopy)
End Using
End Using
Next
pthCopy.Dispose()
NewClip.Dispose()
If OldClip IsNot Nothing Then G.Clip = OldClip Else G.ResetClip()
End Sub
End Module
Voila donc pour le module Draw c'est bon.
Ensuite on va codé la ProgressBar.
Donc moi je l'appel ProgressBarGTP vous vous modifiez si vous voulez.
Code:
Public Class ProgressBarGTP
Inherits Control

Ensuite on va faire les Propriétés de la progressbar c'est à dire ce que l'utilisateur peut modifié.
Par exemple ceci :

Code:
#Region "Var & Propeties"
Private _Value As Integer = 100
Private _Thickness As Integer = 15
Private _Angle As Integer = -90
Private _Symbol As String = "%"
Private _ValueText As Boolean = True
Private _ShadowColor As Color = Color.Gray
Private _GroundColor As Color = Color.FromArgb(64, 0, 0, 0)
Private _BarColor1 As Color = Color.DarkOrange
Private _BarColor2 As Color = Color.Yellow
Private _BarColor3 As Color = Color.GreenYellow
Private _BarThickness As Integer = 20
Private _MaxValue As Integer = 100
Private _AvoidAngle As Integer = 90
Private _3DEffect As Boolean = True
Private _BarColorMode As LinearGradientMode = LinearGradientMode.ForwardDiagonal
Private _EndBarForm As LineCap = LineCap.Round
Donc ensuite on fait ce sub :
Code:
Sub New()
SetStyle(ControlStyles.OptimizedDoubleBuffer, True)
SetStyle(ControlStyles.SupportsTransparentBackColor, True)
BackColor = Color.Transparent
ForeColor = Color.Gray
Font = New Font("Arial", 13)
Size = New Size(125, 125)
Invalidate()
End Sub

Puis pour finir :
Code:
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
MyBase.OnPaint(e)
If Me.Width < 24 Then Me.Width = 24 : If Me.Height < 24 Then Me.Height = 24
Dim i As Integer = (360 - (AvoidAngle)) / MaxValue * _Value
Using B1 As New Bitmap(Width, Height)
Using G As Graphics = Graphics.FromImage(B1)
G.TextRenderingHint = Drawing.Text.TextRenderingHint.AntiAlias
G.SmoothingMode = SmoothingMode.AntiAlias
DoubleBuffered = True
Dim TBrush1 As TextureBrush = NoiseBrush(New Color() {Color.FromArgb(10, BackColor), Color.FromArgb(10, Color.Gray), Color.FromArgb(10, Color.DarkGray)})
G.FillRectangle(TBrush1, ClientRectangle)
Dim GP2 As GraphicsPath = New GraphicsPath()
GP2.AddEllipse(ClientRectangle)
Dim PGB2 As PathGradientBrush = New PathGradientBrush(GP2)
PGB2.CenterPoint = New PointF(Width / 2, Height / 2)
PGB2.CenterColor = Color.FromArgb(128, ShadowColor)
PGB2.SurroundColors = New Color() {Color.Transparent}
PGB2.SetBlendTriangularShape(0.3, 1)
PGB2.FocusScales = New PointF(0.4, 0.4)
G.FillPath(PGB2, GP2)
PGB2.Dispose() : GP2.Dispose()
Using LGB As New LinearGradientBrush(ClientRectangle, GroundColor, GroundColor, LinearGradientMode.Vertical)
Using P1 As New Pen(LGB, Thickness)
G.DrawArc(P1, CInt(Thickness / 2) + 9, CInt(Thickness / 2) + 9, Width - Thickness - 18, Height - Thickness - 18, -90, 360)
End Using
End Using
Using LGB1 As New LinearGradientBrush(ClientRectangle, Color.Black, Color.Black, BarColorMode)
Using P1 As New Pen(LGB1, BarThickness)
Dim gp1 As New GraphicsPath
Dim CB As New ColorBlend
CB.Colors = New Color() {BarColor1, BarColor2, BarColor3}
CB.Positions = New Single() {0.0F, 0.5F, 1.0F}
LGB1.InterpolationColors = CB
P1.Brush = LGB1
P1.EndCap = EndBarForm
G.DrawArc(P1, CInt(Thickness / 2) + 9, CInt(Thickness / 2) + 9, Width - Thickness - 18, Height - Thickness - 18, CInt(_Angle + (AvoidAngle / 2)), i)
If _3DEffect Then
Dim LGB2 As New LinearGradientBrush(ClientRectangle, Color.FromArgb(48, Color.White), Color.FromArgb(48, Color.Black), 90)
Dim P2 As New Pen(LGB2, BarThickness / 2)
P2.EndCap = EndBarForm
G.DrawArc(P2, CInt(Thickness / 2) + 4, CInt(Thickness / 2) + 4, Width - Thickness - 8, Height - Thickness - 8, CInt(_Angle + (AvoidAngle / 2)), i)
End If
End Using
End Using
If TextVisible Then
G.DrawString(_Value & _Symbol, Font, New SolidBrush(ForeColor), New Point(Me.Width / 2 - G.MeasureString(_Value & _Symbol, Font).Width / 2 + 1, Me.Height / 2 - G.MeasureString(_Value & "%", Font).Height / 2 + 1))
End If
End Using
e.Graphics.DrawImage(B1, 0, 0)
End Using
End Sub
Voila votre progressbar arrondie est codé vous avez qu'à générer votre projet et elle va apparaître ici :

Elle s'utilise comme une progressbar normal
Voila donc votre item en VB est créer !

Vous devez être inscrit pour voir les liens ! Inscrivez-vous ou connectez-vous ici.
Utilisé la ProgressBar arrondie dans un autre langage.
Donc si vous voulez utilisé l'item dans un autre langage moi ce sera en C#

Vous allez créer une dll en VB.NET :

Et vous allez y collé tout le code entier.
Si vous ne voulez pas vous faire chier

Code:
Imports System.Drawing.Drawing2D
Imports System.Drawing
Imports System.Windows.Forms
Imports System.Drawing.Text
Imports System.ComponentModel
Enum MouseState As Byte
Normal = 0
Hovered = 1
Pushed = 2
Disabled = 3
End Enum
Module Draw
Public Sub drawcorners(ByVal B As Bitmap, ByVal c As Color)
B.SetPixel(0, 0, c)
B.SetPixel(1, 0, c)
B.SetPixel(0, 1, c)
B.SetPixel(B.Width - 1, 0, c)
B.SetPixel(B.Width - 1, 1, c)
B.SetPixel(B.Width - 2, 0, c)
B.SetPixel(B.Width - 1, B.Height - 1, c)
B.SetPixel(B.Width - 1, B.Height - 2, c)
B.SetPixel(B.Width - 2, B.Height - 1, c)
B.SetPixel(0, B.Height - 1, c)
B.SetPixel(0, B.Height - 2, c)
B.SetPixel(1, B.Height - 1, c)
End Sub
Public Function GetBrush(ByVal c As Color) As SolidBrush
Return New SolidBrush(c)
End Function
Public Function GetPen(ByVal c As Color) As Pen
Return New Pen(New SolidBrush(c))
End Function
Function NoiseBrush(Colors As Color()) As TextureBrush
Dim B As New Bitmap(128, 128)
Dim R As New Random(128)
For X As Integer = 0 To B.Width - 1
For Y As Integer = 0 To B.Height - 1
B.SetPixel(X, Y, Colors(R.Next(Colors.Length)))
Next
Next
Dim T As New TextureBrush(B)
B.Dispose()
Return T
End Function
Public Sub InnerGlow(ByVal G As Graphics, ByVal Rectangle As Rectangle, ByVal Colors As Color())
Dim SubtractTwo As Integer = 1
Dim AddOne As Integer = 0
For Each c In Colors
G.DrawRectangle(New Pen(New SolidBrush(Color.FromArgb(c.R, c.B, c.G))), Rectangle.X + AddOne, Rectangle.Y + AddOne, Rectangle.Width - SubtractTwo, Rectangle.Height - SubtractTwo)
SubtractTwo += 2
AddOne += 1
Next
End Sub
Public Sub InnerGlowRounded(ByVal G As Graphics, ByVal Rectangle As Rectangle, ByVal Degree As Integer, ByVal Colors As Color())
Dim SubtractTwo As Integer = 1
Dim AddOne As Integer = 0
For Each c In Colors
G.DrawPath(New Pen(New SolidBrush(Color.FromArgb(c.R, c.B, c.G))), Draw.RoundRect(Rectangle.X + AddOne, Rectangle.Y + AddOne, Rectangle.Width - SubtractTwo, Rectangle.Height - SubtractTwo, Degree))
SubtractTwo += 2
AddOne += 1
Next
End Sub
'r
Function ToBrush(ByVal A As Integer, ByVal R As Integer, ByVal G As Integer, ByVal B As Integer) As Brush
Return New SolidBrush(Color.FromArgb(A, R, G, B))
End Function
Function ToBrush(ByVal R As Integer, ByVal G As Integer, ByVal B As Integer) As Brush
Return New SolidBrush(Color.FromArgb(R, G, B))
End Function
Function ToBrush(ByVal A As Integer, ByVal C As Color) As Brush
Return New SolidBrush(Color.FromArgb(A, C))
End Function
Function ToBrush(ByVal Pen As Pen) As Brush
Return New SolidBrush(Pen.Color)
End Function
Function ToBrush(ByVal Color As Color) As Brush
Return New SolidBrush(Color)
End Function
Function ToPen(ByVal A As Integer, ByVal R As Integer, ByVal G As Integer, ByVal B As Integer) As Pen
Return New Pen(New SolidBrush(Color.FromArgb(A, R, G, B)))
End Function
Function ToPen(ByVal R As Integer, ByVal G As Integer, ByVal B As Integer) As Pen
Return New Pen(New SolidBrush(Color.FromArgb(R, G, B)))
End Function
Function ToPen(ByVal A As Integer, ByVal C As Color) As Pen
Return New Pen(New SolidBrush(Color.FromArgb(A, C)))
End Function
Function ToPen(ByVal Brush As SolidBrush) As Pen
Return New Pen(Brush)
End Function
Function ToPen(ByVal Color As Color) As Pen
Return New Pen(New SolidBrush(Color))
End Function
Public Function RoundRect(ByVal Rectangle As Rectangle, ByVal Curve As Integer) As GraphicsPath
Dim P As GraphicsPath = New GraphicsPath()
Dim ArcRectangleWidth As Integer = Curve * 2
P.FillMode = FillMode.Winding
P.AddArc(New Rectangle(Rectangle.X, Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), -180, 90)
P.AddArc(New Rectangle(Rectangle.Width - ArcRectangleWidth + Rectangle.X, Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), -90, 90)
P.AddArc(New Rectangle(Rectangle.Width - ArcRectangleWidth + Rectangle.X, Rectangle.Height - ArcRectangleWidth + Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), 0, 90)
P.AddArc(New Rectangle(Rectangle.X, Rectangle.Height - ArcRectangleWidth + Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), 90, 90)
P.AddLine(New Point(Rectangle.X, Rectangle.Height - ArcRectangleWidth + Rectangle.Y), New Point(Rectangle.X, Curve + Rectangle.Y))
P.CloseAllFigures()
Return P
End Function
Public Function RoundRect(ByVal X As Integer, ByVal Y As Integer, ByVal Width As Integer, ByVal Height As Integer, ByVal Curve As Integer) As GraphicsPath
Dim Rectangle As Rectangle = New Rectangle(X, Y, Width, Height)
Dim P As GraphicsPath = New GraphicsPath()
P.FillMode = FillMode.Winding
Dim ArcRectangleWidth As Integer = Curve * 2
P.AddArc(New Rectangle(Rectangle.X, Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), -180, 90)
P.AddArc(New Rectangle(Rectangle.Width - ArcRectangleWidth + Rectangle.X, Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), -90, 90)
P.AddArc(New Rectangle(Rectangle.Width - ArcRectangleWidth + Rectangle.X, Rectangle.Height - ArcRectangleWidth + Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), 0, 90)
P.AddArc(New Rectangle(Rectangle.X, Rectangle.Height - ArcRectangleWidth + Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), 90, 90)
P.AddLine(New Point(Rectangle.X, Rectangle.Height - ArcRectangleWidth + Rectangle.Y), New Point(Rectangle.X, Curve + Rectangle.Y))
P.CloseAllFigures()
Return P
End Function
Public Sub DrawDropShadow(G As Graphics, Color As Color, pth As GraphicsPath, size As Integer, Optional Angle As Single = 120, Optional Distance As Single = 0, Optional Opacity As Single = 1, Optional Spread As Single = 2)
If Angle > 360 Then Angle = 360 * (Angle / 360 - Math.Floor(Angle / 360))
If Angle < 0 Then Angle = 360 * (Angle / 360 - Math.Floor(Angle / 360))
If Distance < 0 Then Throw New Exception("The distance have to be => 0")
If Opacity < 0 Or Opacity > 1 Then Throw New Exception("The opacity have to be between 1 and 0")
Dim pthCopy As GraphicsPath = pth.Clone
size *= 2 '
Dim xi As Double = Math.Cos((Math.PI / 180) * (Angle - 90)) * Distance
Dim yi As Double = Math.Sin((Math.PI / 180) * (Angle - 90)) * Distance
If Distance > 0 Then pthCopy.Transform(New Matrix(1, 0, 0, 1, xi, yi))
Dim OldClip As Region = G.Clip
Dim NewClip As GraphicsPath = pth.Clone
Dim b = NewClip.GetBounds
NewClip.Transform(New Matrix((b.Width - 1) / b.Width, 0, 0, (b.Height - 1) / b.Height, 0.5, 0.5))
NewClip.AddRectangle(New RectangleF((b.X - size) * 2, (b.Y - size) * 2, (b.Width + size) * 2, (b.Height + size) * 2))
G.SetClip(NewClip)
For i = 0 To size
b = pthCopy.GetBounds
Using m As New Matrix((b.Width + 1) / b.Width, 0, 0, (b.Height + 1) / b.Height, -0.5, -0.5)
Using br As New SolidBrush(Color.FromArgb((((255 - Math.Pow(i / size, 1 + Spread) * 255) * Opacity) / size), Color))
pthCopy.Transform(m)
G.FillPath(br, pthCopy)
End Using
End Using
Next
pthCopy.Dispose()
NewClip.Dispose()
If OldClip IsNot Nothing Then G.Clip = OldClip Else G.ResetClip()
End Sub
End Module
Public Class ProgressBarGTP
Inherits Control
#Region "Var & Propeties"
Private _Value As Integer = 100
Private _Thickness As Integer = 15
Private _Angle As Integer = -90
Private _Symbol As String = "%"
Private _ValueText As Boolean = True
Private _ShadowColor As Color = Color.Gray
Private _GroundColor As Color = Color.FromArgb(64, 0, 0, 0)
Private _BarColor1 As Color = Color.DarkOrange
Private _BarColor2 As Color = Color.Yellow
Private _BarColor3 As Color = Color.GreenYellow
Private _BarThickness As Integer = 20
Private _MaxValue As Integer = 100
Private _AvoidAngle As Integer = 90
Private _3DEffect As Boolean = True
Private _BarColorMode As LinearGradientMode = LinearGradientMode.ForwardDiagonal
Private _EndBarForm As LineCap = LineCap.Round
Public Property EndBarForm As LineCap
Get
Return _EndBarForm
End Get
Set(value As LineCap)
_EndBarForm = value : Invalidate()
End Set
End Property
Public Property BarColorMode As LinearGradientMode
Get
Return _BarColorMode
End Get
Set(value As LinearGradientMode)
_BarColorMode = value : Invalidate()
End Set
End Property
Public Property EffectEnabled As Boolean
Get
Return _3DEffect
End Get
Set(value As Boolean)
_3DEffect = value : Invalidate()
End Set
End Property
Public Property GroundColor As Color
Get
Return _GroundColor
End Get
Set(value As Color)
_GroundColor = value : Invalidate()
End Set
End Property
Public Property BarColor1 As Color
Get
Return _BarColor1
End Get
Set(value As Color)
_BarColor1 = value : Invalidate()
End Set
End Property
Public Property BarColor2 As Color
Get
Return _BarColor2
End Get
Set(value As Color)
_BarColor2 = value : Invalidate()
End Set
End Property
Public Property BarColor3 As Color
Get
Return _BarColor3
End Get
Set(value As Color)
_BarColor3 = value : Invalidate()
End Set
End Property
Public Property ShadowColor As Color
Get
Return _ShadowColor
End Get
Set(value As Color)
_ShadowColor = value : Invalidate()
End Set
End Property
Event ValueChanged()
Public Property Value As Integer
Get
Return _Value
End Get
Set(ByVal v As Integer)
If v > MaxValue Or v < 0 Then
_Value = _Value
Else
_Value = v : Invalidate()
End If
RaiseEvent ValueChanged()
End Set
End Property
Public Property MaxValue As Integer
Get
Return _MaxValue
End Get
Set(ByVal value As Integer)
_MaxValue = value : Invalidate()
End Set
End Property
Public Property TextVisible As Boolean
Get
Return _ValueText
End Get
Set(ByVal value As Boolean)
_ValueText = value : Invalidate()
End Set
End Property
Public Property Angle() As Integer
Get
Return _Angle
End Get
Set(ByVal v As Integer)
_Angle = v : Invalidate()
End Set
End Property
Public Property AvoidAngle() As Integer
Get
Return _AvoidAngle
End Get
Set(ByVal v As Integer)
If v < 0 Or v >= 360 Then
_AvoidAngle = _AvoidAngle
Else
_AvoidAngle = v : Invalidate()
End If
End Set
End Property
Public Property Symbol() As String
Get
Return _Symbol
End Get
Set(ByVal v As String)
_Symbol = v : Invalidate()
End Set
End Property
Public Property Thickness() As Integer
Get
Return _Thickness
End Get
Set(ByVal v As Integer)
_Thickness = v : Invalidate()
End Set
End Property
Public Property BarThickness() As Integer
Get
Return _BarThickness
End Get
Set(ByVal v As Integer)
_BarThickness = v : Invalidate()
End Set
End Property
#End Region
Sub New()
SetStyle(ControlStyles.OptimizedDoubleBuffer, True)
SetStyle(ControlStyles.SupportsTransparentBackColor, True)
BackColor = Color.Transparent
ForeColor = Color.Gray
Font = New Font("Arial", 13)
Size = New Size(125, 125)
Invalidate()
End Sub
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
MyBase.OnPaint(e)
If Me.Width < 24 Then Me.Width = 24 : If Me.Height < 24 Then Me.Height = 24
Dim i As Integer = (360 - (AvoidAngle)) / MaxValue * _Value
Using B1 As New Bitmap(Width, Height)
Using G As Graphics = Graphics.FromImage(B1)
G.TextRenderingHint = Drawing.Text.TextRenderingHint.AntiAlias
G.SmoothingMode = SmoothingMode.AntiAlias
DoubleBuffered = True
Dim TBrush1 As TextureBrush = NoiseBrush(New Color() {Color.FromArgb(10, BackColor), Color.FromArgb(10, Color.Gray), Color.FromArgb(10, Color.DarkGray)})
G.FillRectangle(TBrush1, ClientRectangle)
Dim GP2 As GraphicsPath = New GraphicsPath()
GP2.AddEllipse(ClientRectangle)
Dim PGB2 As PathGradientBrush = New PathGradientBrush(GP2)
PGB2.CenterPoint = New PointF(Width / 2, Height / 2)
PGB2.CenterColor = Color.FromArgb(128, ShadowColor)
PGB2.SurroundColors = New Color() {Color.Transparent}
PGB2.SetBlendTriangularShape(0.3, 1)
PGB2.FocusScales = New PointF(0.4, 0.4)
G.FillPath(PGB2, GP2)
PGB2.Dispose() : GP2.Dispose()
Using LGB As New LinearGradientBrush(ClientRectangle, GroundColor, GroundColor, LinearGradientMode.Vertical)
Using P1 As New Pen(LGB, Thickness)
G.DrawArc(P1, CInt(Thickness / 2) + 9, CInt(Thickness / 2) + 9, Width - Thickness - 18, Height - Thickness - 18, -90, 360)
End Using
End Using
Using LGB1 As New LinearGradientBrush(ClientRectangle, Color.Black, Color.Black, BarColorMode)
Using P1 As New Pen(LGB1, BarThickness)
Dim gp1 As New GraphicsPath
Dim CB As New ColorBlend
CB.Colors = New Color() {BarColor1, BarColor2, BarColor3}
CB.Positions = New Single() {0.0F, 0.5F, 1.0F}
LGB1.InterpolationColors = CB
P1.Brush = LGB1
P1.EndCap = EndBarForm
G.DrawArc(P1, CInt(Thickness / 2) + 9, CInt(Thickness / 2) + 9, Width - Thickness - 18, Height - Thickness - 18, CInt(_Angle + (AvoidAngle / 2)), i)
If _3DEffect Then
Dim LGB2 As New LinearGradientBrush(ClientRectangle, Color.FromArgb(48, Color.White), Color.FromArgb(48, Color.Black), 90)
Dim P2 As New Pen(LGB2, BarThickness / 2)
P2.EndCap = EndBarForm
G.DrawArc(P2, CInt(Thickness / 2) + 4, CInt(Thickness / 2) + 4, Width - Thickness - 8, Height - Thickness - 8, CInt(_Angle + (AvoidAngle / 2)), i)
End If
End Using
End Using
If TextVisible Then
G.DrawString(_Value & _Symbol, Font, New SolidBrush(ForeColor), New Point(Me.Width / 2 - G.MeasureString(_Value & _Symbol, Font).Width / 2 + 1, Me.Height / 2 - G.MeasureString(_Value & "%", Font).Height / 2 + 1))
End If
End Using
e.Graphics.DrawImage(B1, 0, 0)
End Using
End Sub
End Class
Vous allez avoir beaucoup d'erreur donc vous allez ajouter c'est dll :
- System.Windows.Forms
- System.Drawing

Ce message est normal vous faites OK
Ensuite vous créez votre projet en C# une fois créer vous cliquez sur la boite à outil ( clique droit ) puis Choisir les éléments

Une fois la page charger il faut cliquer sur Parcourir puis chercher la dll dans le dossier

Une fois ceci fait vous aurez l'item ProgressBarGTP
Vous cliquez sur OK et vous aurez votre item


Donc maintenant on ce retrouve pour la seconde partie qui est la progressbar normal.
Donc comme le nombre de caractères sur RG est limité :/ je ne vais pas tout refaire comme je voulais faire seulement vous ajoutez le code de la progressbar, vous devez mettre toutes les fonctions disponible dans la première partie.

Voila le code a mettre dans la classe :
Code:
Public Class ProgressBarGTP
Inherits Control
Private _Value As Integer = 50
Private _Thickness As Integer = 20
Private _Symbol As String = "%"
Private _ValueText As Boolean = True
Private _GlowColor As Color = Color.Gold
Private _GroundColor As Color = Color.Silver
Private _BarColor1 As Color = Color.DarkOrange
Private _BarColor2 As Color = Color.Yellow
Private _BarColor3 As Color = Color.GreenYellow
Private _MaxValue As Integer = 100
Private _GlowEnabled As Boolean = True
Private _LinesEnabled As Boolean = True
Private _Angle As Integer = 0
Private _LinesColor As Color = Color.Black
Sub New()
Me.SetStyle(ControlStyles.DoubleBuffer Or _
ControlStyles.AllPaintingInWmPaint Or _
ControlStyles.ResizeRedraw Or _
ControlStyles.UserPaint Or _
ControlStyles.Selectable Or _
ControlStyles.SupportsTransparentBackColor, True)
BackColor = Color.Transparent
ForeColor = Color.Gray
Font = New Font("Arial", 10)
Size = New Size(125, 25)
Invalidate()
End Sub
Public Property Angle As Integer
Get
Return _Angle
End Get
Set(value As Integer)
_Angle = value : Invalidate()
End Set
End Property
Public Property GlowEnabled As Boolean
Get
Return _GlowEnabled
End Get
Set(value As Boolean)
_GlowEnabled = value : Invalidate()
End Set
End Property
Public Property LinesEnabled As Boolean
Get
Return _LinesEnabled
End Get
Set(value As Boolean)
_LinesEnabled = value : Invalidate()
End Set
End Property
Public Property GroundColor As Color
Get
Return _GroundColor
End Get
Set(value As Color)
_GroundColor = value : Invalidate()
End Set
End Property
Public Property BarColor1 As Color
Get
Return _BarColor1
End Get
Set(value As Color)
_BarColor1 = value : Invalidate()
End Set
End Property
Public Property BarColor2 As Color
Get
Return _BarColor2
End Get
Set(value As Color)
_BarColor2 = value : Invalidate()
End Set
End Property
Public Property BarColor3 As Color
Get
Return _BarColor3
End Get
Set(value As Color)
_BarColor3 = value : Invalidate()
End Set
End Property
Public Property GlowColor As Color
Get
Return _GlowColor
End Get
Set(value As Color)
_GlowColor = value : Invalidate()
End Set
End Property
Event ValueChanged()
Public Property Value As Integer
Get
Return _Value
End Get
Set(ByVal v As Integer)
If v > MaxValue Or v < 0 Then
_Value = _Value
Else
_Value = v : Invalidate()
End If
RaiseEvent ValueChanged()
End Set
End Property
Public Property MaxValue As Integer
Get
Return _MaxValue
End Get
Set(ByVal value As Integer)
_MaxValue = value : Invalidate()
End Set
End Property
Public Property TextVisible As Boolean
Get
Return _ValueText
End Get
Set(ByVal value As Boolean)
_ValueText = value : Invalidate()
End Set
End Property
Public Property Symbol() As String
Get
Return _Symbol
End Get
Set(ByVal v As String)
_Symbol = v : Invalidate()
End Set
End Property
Public Property Thickness() As Integer
Get
Return _Thickness
End Get
Set(ByVal v As Integer)
_Thickness = v : Invalidate()
End Set
End Property
Public Property LinesColor As Color
Get
Return _LinesColor
End Get
Set(value As Color)
_LinesColor = value : Invalidate()
End Set
End Property
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
MyBase.OnPaint(e)
Size = New Size(Width, Thickness + 10) : Me.Update()
Dim Track As Size = New Size(20, 20)
Dim TS As Integer
Using B1 As New Bitmap(Width, Height)
Using G As Graphics = Graphics.FromImage(B1)
If TextVisible Then
TS = G.MeasureString(_Value & _Symbol, Font).Width - 10
Else
TS = -10
End If
G.TextRenderingHint = Drawing.Text.TextRenderingHint.AntiAlias
G.Clear(BackColor)
G.SmoothingMode = SmoothingMode.AntiAlias
Dim TBrush1 As TextureBrush = NoiseBrush(New Color() {Color.FromArgb(10, BackColor), Color.FromArgb(10, Color.Gray), Color.FromArgb(10, Color.DarkGray)})
G.FillRectangle(TBrush1, ClientRectangle)
Dim Base As GraphicsPath = RoundRect(5, CInt((Height / 2) - CInt(Thickness / 2)), Width - 20 - TS, Thickness, CInt(Thickness / 2) - CInt(Thickness * 0.2))
Dim BackLine As LinearGradientBrush = New LinearGradientBrush(New Point(5, CInt((Height / 2) - CInt(Thickness / 2))), New Point(5, CInt((Height / 2) + CInt(Thickness / 2))), Color.FromArgb(25, Color.Black), Color.FromArgb(25, GroundColor))
G.FillPath(BackLine, Base)
BackLine.Dispose()
If Value <> 0 Then
Dim Bar As GraphicsPath = RoundRect(5, CInt((Height / 2) - CInt(Thickness / 2)), CInt((Width - 20 - TS) * (Value / MaxValue)), Thickness, CInt(Thickness / 2) - CInt(Thickness * 0.2))
If GlowEnabled Then
If Thickness >= 10 Then
DrawDropShadow(G, GlowColor, Bar, 3, 0, , 0.4, 3)
DrawDropShadow(G, GlowColor, Bar, 3, 90, , 0.4, 3)
End If
End If
Dim BarLGB1 As LinearGradientBrush = New LinearGradientBrush(New Rectangle(New Point(4, CInt((Height / 2) - CInt(Thickness / 2))), New Point(Width - 8 - TS, CInt((Height / 2 - TS) + CInt(Thickness / 2)))), Color.Transparent, Color.FromArgb(40, Color.Black), Angle)
Dim CB As New ColorBlend
CB.Colors = New Color() {BarColor1, BarColor2, BarColor3}
CB.Positions = New Single() {0.0F, 0.5F, 1.0F}
BarLGB1.InterpolationColors = CB
G.FillPath(BarLGB1, Bar)
Dim BarLGB2 As LinearGradientBrush = New LinearGradientBrush(New Point(1, CInt((Height / 2) - CInt(Thickness / 2))), New Point(1, CInt((Height / 2) + CInt(Thickness / 2))), Color.Transparent, Color.FromArgb(40, Color.Black))
G.FillPath(BarLGB2, Bar)
If LinesEnabled Then
Dim LinesLGB1 As New LinearGradientBrush(ClientRectangle, Color.Black, Color.Black, 90)
Dim CB2 As New ColorBlend
CB2.Colors = New Color() {Color.Transparent, Color.FromArgb(32, LinesColor), Color.Transparent}
CB2.Positions = New Single() {0, 1 / 2, 1}
LinesLGB1.InterpolationColors = CB2
For i = 5 To CInt((Width - TS) * (Value / MaxValue)) Step 45
G.DrawLine(New Pen(LinesLGB1, 20), New Point(i, CInt((Height / 2) - Thickness * 2)), New Point(i - Thickness * 2, CInt((Height / 2) + Thickness * 2)))
Next
End If
End If
G.DrawPath(ToPen(50, Color.Black), Base)
If TextVisible Then
G.DrawString(_Value & _Symbol, Font, New SolidBrush(ForeColor), New Point(Me.Width - 5 - G.MeasureString(_Value & Symbol, Font).Width, Me.Height / 2 - G.MeasureString(_Value & Symbol, Font).Height / 2 + 2))
End If
End Using
e.Graphics.DrawImage(B1, 0, 0)
End Using
End Sub
End Class
Pour l'utiliser par exemple en C# c'est pareil que l'autre il faut mettre dans une dll et l'importer ( Chapitre 2 )


FIN DU TUTORIEL

Sujet rédigé entièrement par Boosterz GTP
