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
| Public Class Class1
Inherits System.Windows.Forms.Panel
Private _Couleur1 As Color = Color.Red
<System.ComponentModel.DefaultValueAttribute(GetType(System.Drawing.Color), "Window"), _
System.ComponentModel.CategoryAttribute("Appearance")> _
Public Property Couleur1() As Color
Get
Return _Couleur1
End Get
Set(ByVal Value As Color)
_Couleur1 = Value
Invalidate()
End Set
End Property
Private _Couleur2 As Color = Color.White
<System.ComponentModel.DefaultValueAttribute(GetType(System.Drawing.Color), "Window"), _
System.ComponentModel.CategoryAttribute("Appearance")> _
Public Property Couleur2() As Color
Get
Return _Couleur2
End Get
Set(ByVal Value As Color)
_Couleur2 = Value
Invalidate()
End Set
End Property
<Flags()> _
Public Enum Coins
None = 0
TopLeft = 1
TopRight = 2
BottomLeft = 4
BottomRight = 8
All = TopLeft Or TopRight Or BottomLeft Or BottomRight
AllTop = TopLeft Or TopRight
AllLeft = TopLeft Or BottomLeft
AllRight = TopRight Or BottomRight
AllBottom = BottomLeft Or BottomRight
End Enum
Private _Coin As Coins = Coins.All
<System.ComponentModel.DefaultValueAttribute(GetType(Coins), "All"), _
System.ComponentModel.CategoryAttribute("Appearance")> _
Public Property Coin() As Coins
Get
Return Me._Coin
End Get
Set(ByVal Value As Coins)
Me._Coin = Value
If Me.DesignMode = True Then
Me.Invalidate()
End If
End Set
End Property
Private _CoinTaille As Integer = 30
<System.ComponentModel.DefaultValueAttribute(GetType(Integer), "30"), _
System.ComponentModel.CategoryAttribute("Appearance"), _
System.ComponentModel.DescriptionAttribute("The radius of the curve used to paint the corners of the control.")> _
Public Property Cointaille() As Integer
Get
Return Me._CoinTaille
End Get
Set(ByVal Value As Integer)
Me._CoinTaille = Value
If Me.DesignMode = True Then
Me.Invalidate()
End If
End Set
End Property
Public Function RoundCorners(ByVal Rectangle As RectangleF, Optional ByVal Radius As Integer = 5, Optional ByVal Corners As Coins = Coins.All) As Drawing2D.GraphicsPath
Dim p As New Drawing2D.GraphicsPath
Dim x As Single = Rectangle.X
Dim y As Single = Rectangle.Y
Dim w As Single = Rectangle.Width
Dim h As Single = Rectangle.Height
Dim r As Integer = Radius
p.StartFigure()
If CBool(Corners And Coins.TopLeft) Then
p.AddArc(New RectangleF(x, y, 2 * r, 2 * r), 180, 90)
Else
p.AddLine(New PointF(x, y + r), New PointF(x, y))
p.AddLine(New PointF(x, y), New PointF(x + r, y))
End If
p.AddLine(New PointF(x + r, y), New PointF(x + w - r, y))
If CBool(Corners And Coins.TopRight) Then
p.AddArc(New RectangleF(x + w - 2 * r, y, 2 * r, 2 * r), 270, 90)
Else
p.AddLine(New PointF(x + w - r, y), New PointF(x + w, y))
p.AddLine(New PointF(x + w, y), New PointF(x + w, y + r))
End If
p.AddLine(New PointF(x + w, y + r), New PointF(x + w, y + h - r))
If CBool(Corners And Coins.BottomRight) Then
p.AddArc(New RectangleF(x + w - 2 * r, y + h - 2 * r, 2 * r, 2 * r), 0, 90)
Else
p.AddLine(New PointF(x + w, y + h - r), New PointF(x + w, y + h))
p.AddLine(New PointF(x + w, y + h), New PointF(x + w - r, y + h))
End If
p.AddLine(New PointF(x + w - r, y + h), New PointF(x + r, y + h))
If CBool(Corners And Coins.BottomLeft) Then
p.AddArc(New RectangleF(x, y + h - 2 * r, 2 * r, 2 * r), 90, 90)
Else
p.AddLine(New PointF(x + r, y + h), New PointF(x, y + h))
p.AddLine(New PointF(x, y + h), New PointF(x, y + h - r))
End If
p.AddLine(New PointF(x, y + h - r), New PointF(x, y + r))
p.CloseFigure()
Return p
End Function
Protected Overrides Sub OnPaintBackGround(ByVal e As System.Windows.Forms.PaintEventArgs)
MyBase.OnPaintBackground(e)
Dim gp As System.Drawing.Drawing2D.GraphicsPath
Dim Monrec As Rectangle = ClientRectangle
'gp = RoundCorners(New Rectangle(Monrec.X + 2, Monrec.Y + 2, Monrec.Width - 4, Monrec.Height - 4), _CoinTaille, _Coin)
'Dim lgb As System.Drawing.Drawing2D.LinearGradientBrush = New System.Drawing.Drawing2D.LinearGradientBrush(New Rectangle(Monrec.X + 2, Monrec.Y + 2, Monrec.Width - 4, Monrec.Height - 4), _Couleur2, _Couleur1, System.Drawing.Drawing2D.LinearGradientMode.Vertical)
gp = RoundCorners(Monrec, _CoinTaille, _Coin)
Dim lgb As System.Drawing.Drawing2D.LinearGradientBrush = New System.Drawing.Drawing2D.LinearGradientBrush(Monrec, _Couleur2, _Couleur1, System.Drawing.Drawing2D.LinearGradientMode.Vertical)
e.Graphics.FillPath(lgb, gp)
e.Graphics.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
gp.Dispose()
lgb.Dispose()
End Sub
End Class |
Partager