Accueil > > > RECTANGLES ARRONDIS
RECTANGLES ARRONDIS
Information sur la source
Description
Adptation vb.net du source de sebmafate sur www.csharpfr.com : http://www.csharpfr.com/code.aspx?ID=35392 Permet de créer des rectangles arrondis avec des dégradés de couleur (tout le mérite est pour lui)
Source
- Imports System
- Imports System.Collections.Generic
- Imports System.Text
- Imports System.Drawing.Drawing2D
- Imports System.Drawing
- Public Class clsRoundedCorner
- ''' <summary>
- ''' Enregistre les informations n??cessaires ?? la cr??ation d'un Rectangle dont
- ''' les coins sont arrondis
- ''' </summary>
- Public Structure RoundedRectangle
-
- Private x_ As Integer
-
- Private y_ As Integer
-
- Private width_ As Integer
-
- Private height_ As Integer
-
- Private radius_ As Single
-
- Private roundedCorner_ As RoundedCorner
-
- Public Shared Empty As RoundedRectangle
-
- ''' <summary>
- ''' Initialise un rectangle avec les coins arrondis dont le point sup??rieur gauche
- ''' aura pour coordonn??es (<i>x_</i>,<i>y_</i>), comme largeur/hauteur <i>width_</i> et <i>height_</i>, des arrondis
- ''' aux coins <i>rc</i> et enfin les arrondis auront comme rayon <i>radius_</i>
- ''' </summary>
- ''' <param name="x_">Abscisse du point sup??rieur gauche</param>
- ''' <param name="y_">Ordonn??e du point sup??rieur gauche</param>
- ''' <param name="width_">Largeur du rectangle</param>
- ''' <param name="height_">Hauteur du rectangle</param>
- ''' <param name="rc">Coins arrondis</param>
- ''' <param name="radius_">Rayon des arrondis</param>
- Public Sub New(ByVal x_ As Integer, ByVal y_ As Integer, ByVal width_ As Integer, ByVal height_ As Integer, _
- ByVal rc As RoundedCorner, ByVal radius_ As Single)
- Me.x_ = x_
- Me.y_ = y_
- Me.width_ = width_
- Me.height_ = height_
- Me.radius_ = radius_
- Me.roundedCorner_ = rc
- End Sub
-
- ''' <summary>
- ''' Initialise un rectangle ?? partir du Rectangle <i>rect</i>, des arrondis
- ''' aux coins <i>rc</i> et enfin les arrondis auront comme rayon <i>radius_</i>
- ''' </summary>
- ''' <param name="rect">Rectangle de base</param>
- ''' <param name="rc">Coins arrondis</param>
- ''' <param name="radius_">Rayon des arrondis</param>
- Public Sub New(ByVal rect As Rectangle, ByVal rc As RoundedCorner, ByVal radius_ As Single)
- Me.x_ = rect.X
- Me.y_ = rect.Y
- Me.width_ = rect.Width
- Me.height_ = rect.Height
- Me.radius_ = radius_
- Me.roundedCorner_ = rc
- End Sub
-
- ''' <summary>
- ''' Initialise un rectangle avec les coins arrondis dont le point sup??rieur gauche
- ''' aura pour coordonn??es <i>location</i>, comme taille <i>size</i>, des arrondis
- ''' aux coins <i>rc</i> et enfin les arrondis auront comme rayon <i>radius_</i>
- ''' </summary>
- ''' <param name="location"></param>
- ''' <param name="size"></param>
- ''' <param name="rc">Coins arrondis</param>
- ''' <param name="radius_">Rayon des arrondis</param>
- Public Sub New(ByVal location As Point, ByVal size As Size, ByVal rc As RoundedCorner, _
- ByVal radius_ As Single)
- Me.x_ = location.X
- Me.y_ = location.Y
- Me.width_ = size.Width
- Me.height_ = size.Height
- Me.radius_ = radius_
- Me.roundedCorner_ = rc
- End Sub
-
- ''' <summary>
- ''' Obtient ou d??fini une enum??ration indiquant les coins arrondis
- ''' </summary>
- Public Property RoundedCorners() As RoundedCorner
- Get
- Return Me.roundedCorner_
- End Get
- Set(ByVal value As RoundedCorner)
- Me.roundedCorner_ = value
- End Set
- End Property
-
- ''' <summary>
- ''' Obtient ou d??fini la taille du rectangle
- ''' </summary>
- Public Property Size() As Size
- Get
- Return New Size(Me.width_, Me.height_)
- End Get
- Set(ByVal value As Size)
- Me.width_ = value.Width
- Me.height_ = value.Height
- End Set
- End Property
-
- ''' <summary>
- ''' Obtient ou d??fini l'abscisse du coin sup??rieur gauche du rectangle
- ''' </summary>
- Public Property X() As Integer
- Get
- Return Me.x_
- End Get
- Set(ByVal value As Integer)
- Me.x_ = value
- End Set
- End Property
-
- ''' <summary>
- ''' Obtient ou d??fini l'ordonn??e du coin sup??rieur gauche du rectangle
- ''' </summary>
- Public Property Y() As Integer
- Get
- Return Me.y_
- End Get
- Set(ByVal value As Integer)
- Me.y_ = value
- End Set
- End Property
-
- ''' <summary>
- ''' Obtient ou d??fini la largeur du rectangle
- ''' </summary>
- Public Property Width() As Integer
- Get
- Return Me.width_
- End Get
- Set(ByVal value As Integer)
- Me.width_ = value
- End Set
- End Property
-
- ''' <summary>
- ''' Obtient ou d??fini la hauteur du rectangle
- ''' </summary>
- Public Property Height() As Integer
- Get
- Return Me.height_
- End Get
- Set(ByVal value As Integer)
- Me.height_ = value
- End Set
- End Property
-
- ''' <summary>
- ''' Obtient l'abscisse des coins de gauche
- ''' </summary>
- Public ReadOnly Property Left() As Integer
- Get
- Return Me.x_
- End Get
- End Property
-
- ''' <summary>
- ''' Obtient l'abscisse des coins de droit
- ''' </summary>
- Public ReadOnly Property Right() As Integer
- Get
- Return (Me.x_ + Me.width_)
- End Get
- End Property
-
- ''' <summary>
- ''' Obtient l'ordonn??e des coins du haut
- ''' </summary>
- Public ReadOnly Property Top() As Integer
- Get
- Return Me.y_
- End Get
- End Property
-
- ''' <summary>
- ''' Obtient l'ordonn??e des coins du bas
- ''' </summary>
- Public ReadOnly Property Bottom() As Integer
- Get
- Return (Me.y_ + Me.height_)
- End Get
- End Property
-
- ''' <summary>
- ''' Obtient ou d??fini l'emplacement du coin sup??rieur gauche
- ''' </summary>
- Public Property Location() As Point
- Get
- Return New Point(Me.x_, Me.y_)
- End Get
- Set(ByVal value As Point)
- Me.x_ = value.X
- Me.y_ = value.Y
- End Set
- End Property
-
- ''' <summary>
- ''' Obtient ou d??fini le rayon de courbure des coins
- ''' </summary>
- Public Property Radius() As Single
- Get
- Return radius_
- End Get
- Set(ByVal value As Single)
- radius_ = value
- End Set
- End Property
-
- ''' <summary>
- ''' Agrandi le rectangle de la taille sp??cifi??e
- ''' </summary>
- ''' <param name="width_">largeur</param>
- ''' <param name="height_">hauteur</param>
- Public Overloads Sub Inflate(ByVal width_ As Integer, ByVal height_ As Integer)
- Me.x_ = (Me.x_ - width_)
- Me.y_ = (Me.y_ - height_)
- Me.width_ = (Me.width_ + (2 * width_))
- Me.height_ = (Me.height_ + (2 * height_))
- End Sub
-
- ''' <summary>
- ''' Agrandi le rectangle de la taille sp??cifi??e
- ''' </summary>
- ''' <param name="size">taille</param>
- Public Overloads Sub Inflate(ByVal size As Size)
- Me.Inflate(size.Width, size.Height)
- End Sub
-
- ''' <summary>
- ''' Cr??e et retourne une copie RoundedRectangle agrandi de la taille sp??cifi??.
- ''' </summary>
- ''' <param name="rrect">RoundedRectangle</param>
- ''' <param name="width_">Largeur</param>
- ''' <param name="height_">Hauteur</param>
- ''' <returns>Une copie du RoundedRectangle agrandie</returns>
- Public Overloads Shared Function Inflate(ByVal rrect As RoundedRectangle, _
- ByVal width_ As Integer, ByVal height_ As Integer) As RoundedRectangle
- Dim r As RoundedRectangle = rrect
- r.Inflate(width_, height_)
- Return r
- End Function
-
- ''' <summary>
- ''' Retourne un RoundRectangle correspondant ?? l'intersection des RoundRectangles a et b
- ''' </summary>
- ''' <param name="a">RoundedRectangle</param>
- ''' <param name="b">RoundedRectangle</param>
- ''' <param name="rc">Coins ?? arrondir</param>
- ''' <param name="radius_">Rayon de coubure des arrondis</param>
- ''' <returns></returns>
- ''' <remarks>Si aucune intersection n'est trouv??e entre les RoundRectangles, un RoundedRectangle est retourn??</remarks>
- Public Overloads Shared Function Intersect(ByVal a As RoundedRectangle, _
- ByVal b As RoundedRectangle, ByVal rc As RoundedCorner, _
- ByVal radius_ As Single) As RoundedRectangle
- Dim left As Integer = Math.Max(a.Left, b.Left)
- Dim right As Integer = Math.Min(a.Right, b.Right)
- Dim top As Integer = Math.Max(a.Top, b.Top)
- Dim bottom As Integer = Math.Min(a.Bottom, b.Bottom)
- If ((left <= right) _
- AndAlso (top <= bottom)) Then
- Return New RoundedRectangle(left, (right - left), top, (bottom - top), rc, radius_)
- End If
- Return RoundedRectangle.Empty
- End Function
-
- ''' <summary>
- ''' Replace ce RoundedRectangle par l'intersection de celui-ci de rrect
- ''' </summary>
- ''' <param name="rrect">RoundedRectangle</param>
- Public Overloads Sub Intersect(ByVal rrect As RoundedRectangle)
- Dim r As RoundedRectangle = RoundedRectangle.Intersect(rrect, Me, _
- Me.roundedCorner_, Me.radius_)
- Me.x_ = r.x_
- Me.y_ = r.y_
- Me.width_ = r.width_
- Me.height_ = r.height_
- End Sub
-
- ''' <summary>
- ''' Retourne <i>true</i> si ce RoundedRectangle poss??de une intersection avec rrect, <i>false</i> sinon
- ''' </summary>
- ''' <param name="rrect">RoundedRectangle</param>
- ''' <returns><i>true</i> si intersection, <i>false</i> sinon</returns>
- Public Function IntersectWith(ByVal rrect As RoundedRectangle) As Boolean
- Return (((rrect.Left < Me.Right) _
- AndAlso (Me.Left < rrect.Right)) _
- AndAlso ((rrect.Top < Me.Bottom) _
- AndAlso (Me.Top < rrect.Bottom)))
- 'if (((rect.X < (this.X + this.Width)) && (this.X < (rect.X + rect.Width))) && (rect.Y < (this.Y + this.Height)))
- '{
- ' return (this.Y < (rect.Y + rect.Height));
- '}
- 'return false;
- End Function
-
- ''' <summary>
- ''' Retourne un RoundedRectangle qui correspond ?? l'intersection des RoundedRectangle a et b et dont les
- ''' coins <i>rc</i> sont arrondis d'un rayon de <i>radius_</i>
- ''' </summary>
- ''' <param name="a">RoundedRectangle</param>
- ''' <param name="b">RoundedRectangle</param>
- ''' <param name="rc">Coins ?? arrondir</param>
- ''' <param name="radius_">Rayon de courbure des arrondis</param>
- ''' <returns>RoundedRectangle de l'union</returns>
- Public Shared Function Union(ByVal a As RoundedRectangle, _
- ByVal b As RoundedRectangle, ByVal rc As RoundedCorner, _
- ByVal radius_ As Single) As RoundedRectangle
- Dim left As Integer = Math.Min(a.Left, b.Left)
- Dim right As Integer = Math.Max(a.Right, b.Right)
- Dim top As Integer = Math.Min(a.Top, b.Top)
- Dim bottom As Integer = Math.Max(a.Bottom, b.Bottom)
- Return New RoundedRectangle(left, (right - left), top, (bottom - top), rc, radius_)
- End Function
-
- ''' <summary>
- ''' D??place le RoundedRectangle d'apr??s les coordonn??es sp??cifi??s
- ''' </summary>
- ''' <param name="x_">D??placement sur l'axe des abscisses</param>
- ''' <param name="y_">D??placement sur l'axe des ordon??es</param>
- Public Overloads Sub Offset(ByVal x_ As Integer, ByVal y_ As Integer)
- Me.x_ = (Me.x_ + x_)
- Me.y_ = (Me.y_ + y_)
- End Sub
-
- ''' <summary>
- ''' D??place le RoundedRectangle d'apr??s les ccordonn??es sp??cifi??es
- ''' </summary>
- ''' <param name="point">Point contenant les informations de d??placements</param>
- Public Overloads Sub Offset(ByVal point As Point)
- Me.x_ = (Me.x_ + point.X)
- Me.y_ = (Me.y_ + point.Y)
- End Sub
-
- ''' <summary>
- ''' Retourne un bool??en indiquant si le point sp??cifi?? fait partie du RoundedRectangle
- ''' </summary>
- ''' <param name="x_">Abscisse</param>
- ''' <param name="y_">Ordonn??e</param>
- ''' <returns><i>true</i> si le point se trouve ?? l'int??rieur du RoundedRectangle, <i>false</i> sinon</returns>
- Public Overloads Function Contains(ByVal x_ As Integer, ByVal y_ As Integer) As Boolean
- Return ((Me.x_ <= x_) _
- AndAlso ((x_ <= Me.Right) _
- AndAlso ((Me.y_ <= y_) _
- AndAlso (y_ <= Me.Bottom))))
- End Function
-
- ''' <summary>
- ''' Retourne un bool??en indiquant si le point sp??cifi?? fait partie du RoundedRectangle
- ''' </summary>
- ''' <param name="pt">Point ?? v??rifier</param>
- ''' <returns><i>true</i> si le point se trouve ?? l'int??rieur du RoundedRectangle, <i>false</i> sinon</returns>
- Public Overloads Function Contains(ByVal pt As Point) As Boolean
- Return Contains(pt.X, pt.Y)
- End Function
-
- ''' <summary>
- ''' Retourne un <see cref="GraphicsPath"/> repr??sentant le RoundedRectangle.
- ''' </summary>
- ''' <returns><see cref="GraphicsPath"/></returns>
- ''' <seealso cref="GraphicsPath"/>
- Public Function ToGraphicsPath() As GraphicsPath
- Dim gp As GraphicsPath
- 'Dim temp As PointF
- gp = New GraphicsPath
- 'Rectangle baseRect = new Rectangle(this.Location, this.Size);
- ' si le rayon est inf??rieur ou ??gal ?? 0
- ' on retourne le rectangle de base
- If (radius_ <= 0.0!) Then
- gp.AddRectangle(New Rectangle(Me.Location, Me.Size))
- gp.CloseFigure()
- Return gp
- End If
- Dim diameter As Single = (radius_ * 2.0!)
- If (Me.height_ <= Me.width_) Then
- If ((diameter >= Me.height_) _
- AndAlso (((Me.roundedCorner_ _
- And (RoundedCorner.BottomLeft Or RoundedCorner.TopLeft)) _
- = (RoundedCorner.BottomLeft Or RoundedCorner.TopLeft)) _
- OrElse ((Me.roundedCorner_ _
- And (RoundedCorner.BottomRight Or RoundedCorner.TopRight)) _
- = (RoundedCorner.BottomRight Or RoundedCorner.TopRight)))) Then
- diameter = Me.height_
- End If
- ElseIf ((diameter >= Me.width_) _
- AndAlso (((Me.roundedCorner_ _
- And (RoundedCorner.BottomLeft Or RoundedCorner.BottomRight)) _
- = (RoundedCorner.BottomLeft Or RoundedCorner.BottomRight)) _
- OrElse ((Me.roundedCorner_ _
- And (RoundedCorner.TopLeft Or RoundedCorner.TopRight)) _
- = (RoundedCorner.TopLeft Or RoundedCorner.TopRight)))) Then
- diameter = Me.width_
- End If
- Dim size As SizeF = New SizeF(diameter, diameter)
- Dim arc As RectangleF = New RectangleF(Me.Location, size)
- ' arc en haut ?? gauche
- If ((Me.roundedCorner_ And RoundedCorner.TopLeft) _
- = RoundedCorner.TopLeft) Then
- gp.AddArc(arc, 180, 90)
- Else
- gp.AddLine(New PointF(arc.Left, arc.Top), New PointF(arc.Left, arc.Top))
- End If
- ' arc en haut ?? droite
- arc.X = (CType(Me.Right, Single) - diameter)
- If ((Me.roundedCorner_ And RoundedCorner.TopRight) _
- = RoundedCorner.TopRight) Then
- gp.AddArc(arc, 270, 90)
- Else
- gp.AddLine(New PointF(arc.Right, arc.Top), New PointF(arc.Right, arc.Top))
- End If
- arc.Y = (CType(Me.Bottom, Single) - diameter)
- ' arc en bas ?? droite
- If ((Me.roundedCorner_ And RoundedCorner.BottomRight) _
- = RoundedCorner.BottomRight) Then
- gp.AddArc(arc, 0, 90)
- Else
- gp.AddLine(New PointF(arc.Right, arc.Bottom), New PointF(arc.Right, arc.Bottom))
- End If
- ' arc en bas ?? gauche
- arc.X = CType(Me.Left, Single)
- If ((Me.roundedCorner_ And RoundedCorner.BottomLeft) _
- = RoundedCorner.BottomLeft) Then
- gp.AddArc(arc, 90, 90)
- Else
- gp.AddLine(New PointF(arc.Left, arc.Bottom), New PointF(arc.Left, arc.Bottom))
- End If
- gp.CloseFigure()
- Return gp
- End Function
-
- ''' <summary>
- ''' Retourne un <see cref="Rectangle"/>
- ''' </summary>
- ''' <returns><see cref="Rectangle"/></returns>
- Public Function ToRectangle() As Rectangle
- Return New Rectangle(Me.Location, Me.Size)
- End Function
-
- #Region " overrides "
- Public Overrides Function ToString() As String
- Return String.Format("{{X={0},Y={1},Width={2},Height={3},Radius={4}}}", Me.x_, _
- Me.y_, Me.width_, Me.height_, Me.radius_)
- End Function
-
- Public Shared Operator =(ByVal a As RoundedRectangle, ByVal b As RoundedRectangle) As Boolean
- Return (a.X = b.X And a.Y = b.Y And a.Width = b.Width And a.Height = b.Height)
- End Operator
-
- Public Shared Operator <>(ByVal a As RoundedRectangle, ByVal b As RoundedRectangle) As Boolean
- Return Not (a = b)
- End Operator
-
- Public Overrides Function Equals(ByVal obj As Object) As Boolean
- Dim ret As Boolean = False
- If (obj.GetType.Name = GetType(RoundedRectangle).Name) Then
- Dim r As RoundedRectangle = obj
- ret = (r.X = Me.X And r.Y = Me.Y And r.Width = Me.Width And r.Height = Me.Height)
- End If
- Return ret
- End Function
-
- Public Overrides Function GetHashCode() As Integer
- Return Me.GetHashCode()
- End Function
- #End Region
- End Structure
-
- <Flags()> _
- Public Enum RoundedCorner
-
- TopLeft = 2
-
- TopRight = 4
-
- BottomLeft = 8
-
- BottomRight = 16
-
- All = TopLeft Or TopRight Or BottomLeft Or BottomRight
- End Enum
- End Class
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports System.Drawing.Drawing2D
Imports System.Drawing
Public Class clsRoundedCorner
''' <summary>
''' Enregistre les informations n??cessaires ?? la cr??ation d'un Rectangle dont
''' les coins sont arrondis
''' </summary>
Public Structure RoundedRectangle
Private x_ As Integer
Private y_ As Integer
Private width_ As Integer
Private height_ As Integer
Private radius_ As Single
Private roundedCorner_ As RoundedCorner
Public Shared Empty As RoundedRectangle
''' <summary>
''' Initialise un rectangle avec les coins arrondis dont le point sup??rieur gauche
''' aura pour coordonn??es (<i>x_</i>,<i>y_</i>), comme largeur/hauteur <i>width_</i> et <i>height_</i>, des arrondis
''' aux coins <i>rc</i> et enfin les arrondis auront comme rayon <i>radius_</i>
''' </summary>
''' <param name="x_">Abscisse du point sup??rieur gauche</param>
''' <param name="y_">Ordonn??e du point sup??rieur gauche</param>
''' <param name="width_">Largeur du rectangle</param>
''' <param name="height_">Hauteur du rectangle</param>
''' <param name="rc">Coins arrondis</param>
''' <param name="radius_">Rayon des arrondis</param>
Public Sub New(ByVal x_ As Integer, ByVal y_ As Integer, ByVal width_ As Integer, ByVal height_ As Integer, _
ByVal rc As RoundedCorner, ByVal radius_ As Single)
Me.x_ = x_
Me.y_ = y_
Me.width_ = width_
Me.height_ = height_
Me.radius_ = radius_
Me.roundedCorner_ = rc
End Sub
''' <summary>
''' Initialise un rectangle ?? partir du Rectangle <i>rect</i>, des arrondis
''' aux coins <i>rc</i> et enfin les arrondis auront comme rayon <i>radius_</i>
''' </summary>
''' <param name="rect">Rectangle de base</param>
''' <param name="rc">Coins arrondis</param>
''' <param name="radius_">Rayon des arrondis</param>
Public Sub New(ByVal rect As Rectangle, ByVal rc As RoundedCorner, ByVal radius_ As Single)
Me.x_ = rect.X
Me.y_ = rect.Y
Me.width_ = rect.Width
Me.height_ = rect.Height
Me.radius_ = radius_
Me.roundedCorner_ = rc
End Sub
''' <summary>
''' Initialise un rectangle avec les coins arrondis dont le point sup??rieur gauche
''' aura pour coordonn??es <i>location</i>, comme taille <i>size</i>, des arrondis
''' aux coins <i>rc</i> et enfin les arrondis auront comme rayon <i>radius_</i>
''' </summary>
''' <param name="location"></param>
''' <param name="size"></param>
''' <param name="rc">Coins arrondis</param>
''' <param name="radius_">Rayon des arrondis</param>
Public Sub New(ByVal location As Point, ByVal size As Size, ByVal rc As RoundedCorner, _
ByVal radius_ As Single)
Me.x_ = location.X
Me.y_ = location.Y
Me.width_ = size.Width
Me.height_ = size.Height
Me.radius_ = radius_
Me.roundedCorner_ = rc
End Sub
''' <summary>
''' Obtient ou d??fini une enum??ration indiquant les coins arrondis
''' </summary>
Public Property RoundedCorners() As RoundedCorner
Get
Return Me.roundedCorner_
End Get
Set(ByVal value As RoundedCorner)
Me.roundedCorner_ = value
End Set
End Property
''' <summary>
''' Obtient ou d??fini la taille du rectangle
''' </summary>
Public Property Size() As Size
Get
Return New Size(Me.width_, Me.height_)
End Get
Set(ByVal value As Size)
Me.width_ = value.Width
Me.height_ = value.Height
End Set
End Property
''' <summary>
''' Obtient ou d??fini l'abscisse du coin sup??rieur gauche du rectangle
''' </summary>
Public Property X() As Integer
Get
Return Me.x_
End Get
Set(ByVal value As Integer)
Me.x_ = value
End Set
End Property
''' <summary>
''' Obtient ou d??fini l'ordonn??e du coin sup??rieur gauche du rectangle
''' </summary>
Public Property Y() As Integer
Get
Return Me.y_
End Get
Set(ByVal value As Integer)
Me.y_ = value
End Set
End Property
''' <summary>
''' Obtient ou d??fini la largeur du rectangle
''' </summary>
Public Property Width() As Integer
Get
Return Me.width_
End Get
Set(ByVal value As Integer)
Me.width_ = value
End Set
End Property
''' <summary>
''' Obtient ou d??fini la hauteur du rectangle
''' </summary>
Public Property Height() As Integer
Get
Return Me.height_
End Get
Set(ByVal value As Integer)
Me.height_ = value
End Set
End Property
''' <summary>
''' Obtient l'abscisse des coins de gauche
''' </summary>
Public ReadOnly Property Left() As Integer
Get
Return Me.x_
End Get
End Property
''' <summary>
''' Obtient l'abscisse des coins de droit
''' </summary>
Public ReadOnly Property Right() As Integer
Get
Return (Me.x_ + Me.width_)
End Get
End Property
''' <summary>
''' Obtient l'ordonn??e des coins du haut
''' </summary>
Public ReadOnly Property Top() As Integer
Get
Return Me.y_
End Get
End Property
''' <summary>
''' Obtient l'ordonn??e des coins du bas
''' </summary>
Public ReadOnly Property Bottom() As Integer
Get
Return (Me.y_ + Me.height_)
End Get
End Property
''' <summary>
''' Obtient ou d??fini l'emplacement du coin sup??rieur gauche
''' </summary>
Public Property Location() As Point
Get
Return New Point(Me.x_, Me.y_)
End Get
Set(ByVal value As Point)
Me.x_ = value.X
Me.y_ = value.Y
End Set
End Property
''' <summary>
''' Obtient ou d??fini le rayon de courbure des coins
''' </summary>
Public Property Radius() As Single
Get
Return radius_
End Get
Set(ByVal value As Single)
radius_ = value
End Set
End Property
''' <summary>
''' Agrandi le rectangle de la taille sp??cifi??e
''' </summary>
''' <param name="width_">largeur</param>
''' <param name="height_">hauteur</param>
Public Overloads Sub Inflate(ByVal width_ As Integer, ByVal height_ As Integer)
Me.x_ = (Me.x_ - width_)
Me.y_ = (Me.y_ - height_)
Me.width_ = (Me.width_ + (2 * width_))
Me.height_ = (Me.height_ + (2 * height_))
End Sub
''' <summary>
''' Agrandi le rectangle de la taille sp??cifi??e
''' </summary>
''' <param name="size">taille</param>
Public Overloads Sub Inflate(ByVal size As Size)
Me.Inflate(size.Width, size.Height)
End Sub
''' <summary>
''' Cr??e et retourne une copie RoundedRectangle agrandi de la taille sp??cifi??.
''' </summary>
''' <param name="rrect">RoundedRectangle</param>
''' <param name="width_">Largeur</param>
''' <param name="height_">Hauteur</param>
''' <returns>Une copie du RoundedRectangle agrandie</returns>
Public Overloads Shared Function Inflate(ByVal rrect As RoundedRectangle, _
ByVal width_ As Integer, ByVal height_ As Integer) As RoundedRectangle
Dim r As RoundedRectangle = rrect
r.Inflate(width_, height_)
Return r
End Function
''' <summary>
''' Retourne un RoundRectangle correspondant ?? l'intersection des RoundRectangles a et b
''' </summary>
''' <param name="a">RoundedRectangle</param>
''' <param name="b">RoundedRectangle</param>
''' <param name="rc">Coins ?? arrondir</param>
''' <param name="radius_">Rayon de coubure des arrondis</param>
''' <returns></returns>
''' <remarks>Si aucune intersection n'est trouv??e entre les RoundRectangles, un RoundedRectangle est retourn??</remarks>
Public Overloads Shared Function Intersect(ByVal a As RoundedRectangle, _
ByVal b As RoundedRectangle, ByVal rc As RoundedCorner, _
ByVal radius_ As Single) As RoundedRectangle
Dim left As Integer = Math.Max(a.Left, b.Left)
Dim right As Integer = Math.Min(a.Right, b.Right)
Dim top As Integer = Math.Max(a.Top, b.Top)
Dim bottom As Integer = Math.Min(a.Bottom, b.Bottom)
If ((left <= right) _
AndAlso (top <= bottom)) Then
Return New RoundedRectangle(left, (right - left), top, (bottom - top), rc, radius_)
End If
Return RoundedRectangle.Empty
End Function
''' <summary>
''' Replace ce RoundedRectangle par l'intersection de celui-ci de rrect
''' </summary>
''' <param name="rrect">RoundedRectangle</param>
Public Overloads Sub Intersect(ByVal rrect As RoundedRectangle)
Dim r As RoundedRectangle = RoundedRectangle.Intersect(rrect, Me, _
Me.roundedCorner_, Me.radius_)
Me.x_ = r.x_
Me.y_ = r.y_
Me.width_ = r.width_
Me.height_ = r.height_
End Sub
''' <summary>
''' Retourne <i>true</i> si ce RoundedRectangle poss??de une intersection avec rrect, <i>false</i> sinon
''' </summary>
''' <param name="rrect">RoundedRectangle</param>
''' <returns><i>true</i> si intersection, <i>false</i> sinon</returns>
Public Function IntersectWith(ByVal rrect As RoundedRectangle) As Boolean
Return (((rrect.Left < Me.Right) _
AndAlso (Me.Left < rrect.Right)) _
AndAlso ((rrect.Top < Me.Bottom) _
AndAlso (Me.Top < rrect.Bottom)))
'if (((rect.X < (this.X + this.Width)) && (this.X < (rect.X + rect.Width))) && (rect.Y < (this.Y + this.Height)))
'{
' return (this.Y < (rect.Y + rect.Height));
'}
'return false;
End Function
''' <summary>
''' Retourne un RoundedRectangle qui correspond ?? l'intersection des RoundedRectangle a et b et dont les
''' coins <i>rc</i> sont arrondis d'un rayon de <i>radius_</i>
''' </summary>
''' <param name="a">RoundedRectangle</param>
''' <param name="b">RoundedRectangle</param>
''' <param name="rc">Coins ?? arrondir</param>
''' <param name="radius_">Rayon de courbure des arrondis</param>
''' <returns>RoundedRectangle de l'union</returns>
Public Shared Function Union(ByVal a As RoundedRectangle, _
ByVal b As RoundedRectangle, ByVal rc As RoundedCorner, _
ByVal radius_ As Single) As RoundedRectangle
Dim left As Integer = Math.Min(a.Left, b.Left)
Dim right As Integer = Math.Max(a.Right, b.Right)
Dim top As Integer = Math.Min(a.Top, b.Top)
Dim bottom As Integer = Math.Max(a.Bottom, b.Bottom)
Return New RoundedRectangle(left, (right - left), top, (bottom - top), rc, radius_)
End Function
''' <summary>
''' D??place le RoundedRectangle d'apr??s les coordonn??es sp??cifi??s
''' </summary>
''' <param name="x_">D??placement sur l'axe des abscisses</param>
''' <param name="y_">D??placement sur l'axe des ordon??es</param>
Public Overloads Sub Offset(ByVal x_ As Integer, ByVal y_ As Integer)
Me.x_ = (Me.x_ + x_)
Me.y_ = (Me.y_ + y_)
End Sub
''' <summary>
''' D??place le RoundedRectangle d'apr??s les ccordonn??es sp??cifi??es
''' </summary>
''' <param name="point">Point contenant les informations de d??placements</param>
Public Overloads Sub Offset(ByVal point As Point)
Me.x_ = (Me.x_ + point.X)
Me.y_ = (Me.y_ + point.Y)
End Sub
''' <summary>
''' Retourne un bool??en indiquant si le point sp??cifi?? fait partie du RoundedRectangle
''' </summary>
''' <param name="x_">Abscisse</param>
''' <param name="y_">Ordonn??e</param>
''' <returns><i>true</i> si le point se trouve ?? l'int??rieur du RoundedRectangle, <i>false</i> sinon</returns>
Public Overloads Function Contains(ByVal x_ As Integer, ByVal y_ As Integer) As Boolean
Return ((Me.x_ <= x_) _
AndAlso ((x_ <= Me.Right) _
AndAlso ((Me.y_ <= y_) _
AndAlso (y_ <= Me.Bottom))))
End Function
''' <summary>
''' Retourne un bool??en indiquant si le point sp??cifi?? fait partie du RoundedRectangle
''' </summary>
''' <param name="pt">Point ?? v??rifier</param>
''' <returns><i>true</i> si le point se trouve ?? l'int??rieur du RoundedRectangle, <i>false</i> sinon</returns>
Public Overloads Function Contains(ByVal pt As Point) As Boolean
Return Contains(pt.X, pt.Y)
End Function
''' <summary>
''' Retourne un <see cref="GraphicsPath"/> repr??sentant le RoundedRectangle.
''' </summary>
''' <returns><see cref="GraphicsPath"/></returns>
''' <seealso cref="GraphicsPath"/>
Public Function ToGraphicsPath() As GraphicsPath
Dim gp As GraphicsPath
'Dim temp As PointF
gp = New GraphicsPath
'Rectangle baseRect = new Rectangle(this.Location, this.Size);
' si le rayon est inf??rieur ou ??gal ?? 0
' on retourne le rectangle de base
If (radius_ <= 0.0!) Then
gp.AddRectangle(New Rectangle(Me.Location, Me.Size))
gp.CloseFigure()
Return gp
End If
Dim diameter As Single = (radius_ * 2.0!)
If (Me.height_ <= Me.width_) Then
If ((diameter >= Me.height_) _
AndAlso (((Me.roundedCorner_ _
And (RoundedCorner.BottomLeft Or RoundedCorner.TopLeft)) _
= (RoundedCorner.BottomLeft Or RoundedCorner.TopLeft)) _
OrElse ((Me.roundedCorner_ _
And (RoundedCorner.BottomRight Or RoundedCorner.TopRight)) _
= (RoundedCorner.BottomRight Or RoundedCorner.TopRight)))) Then
diameter = Me.height_
End If
ElseIf ((diameter >= Me.width_) _
AndAlso (((Me.roundedCorner_ _
And (RoundedCorner.BottomLeft Or RoundedCorner.BottomRight)) _
= (RoundedCorner.BottomLeft Or RoundedCorner.BottomRight)) _
OrElse ((Me.roundedCorner_ _
And (RoundedCorner.TopLeft Or RoundedCorner.TopRight)) _
= (RoundedCorner.TopLeft Or RoundedCorner.TopRight)))) Then
diameter = Me.width_
End If
Dim size As SizeF = New SizeF(diameter, diameter)
Dim arc As RectangleF = New RectangleF(Me.Location, size)
' arc en haut ?? gauche
If ((Me.roundedCorner_ And RoundedCorner.TopLeft) _
= RoundedCorner.TopLeft) Then
gp.AddArc(arc, 180, 90)
Else
gp.AddLine(New PointF(arc.Left, arc.Top), New PointF(arc.Left, arc.Top))
End If
' arc en haut ?? droite
arc.X = (CType(Me.Right, Single) - diameter)
If ((Me.roundedCorner_ And RoundedCorner.TopRight) _
= RoundedCorner.TopRight) Then
gp.AddArc(arc, 270, 90)
Else
gp.AddLine(New PointF(arc.Right, arc.Top), New PointF(arc.Right, arc.Top))
End If
arc.Y = (CType(Me.Bottom, Single) - diameter)
' arc en bas ?? droite
If ((Me.roundedCorner_ And RoundedCorner.BottomRight) _
= RoundedCorner.BottomRight) Then
gp.AddArc(arc, 0, 90)
Else
gp.AddLine(New PointF(arc.Right, arc.Bottom), New PointF(arc.Right, arc.Bottom))
End If
' arc en bas ?? gauche
arc.X = CType(Me.Left, Single)
If ((Me.roundedCorner_ And RoundedCorner.BottomLeft) _
= RoundedCorner.BottomLeft) Then
gp.AddArc(arc, 90, 90)
Else
gp.AddLine(New PointF(arc.Left, arc.Bottom), New PointF(arc.Left, arc.Bottom))
End If
gp.CloseFigure()
Return gp
End Function
''' <summary>
''' Retourne un <see cref="Rectangle"/>
''' </summary>
''' <returns><see cref="Rectangle"/></returns>
Public Function ToRectangle() As Rectangle
Return New Rectangle(Me.Location, Me.Size)
End Function
#Region " overrides "
Public Overrides Function ToString() As String
Return String.Format("{{X={0},Y={1},Width={2},Height={3},Radius={4}}}", Me.x_, _
Me.y_, Me.width_, Me.height_, Me.radius_)
End Function
Public Shared Operator =(ByVal a As RoundedRectangle, ByVal b As RoundedRectangle) As Boolean
Return (a.X = b.X And a.Y = b.Y And a.Width = b.Width And a.Height = b.Height)
End Operator
Public Shared Operator <>(ByVal a As RoundedRectangle, ByVal b As RoundedRectangle) As Boolean
Return Not (a = b)
End Operator
Public Overrides Function Equals(ByVal obj As Object) As Boolean
Dim ret As Boolean = False
If (obj.GetType.Name = GetType(RoundedRectangle).Name) Then
Dim r As RoundedRectangle = obj
ret = (r.X = Me.X And r.Y = Me.Y And r.Width = Me.Width And r.Height = Me.Height)
End If
Return ret
End Function
Public Overrides Function GetHashCode() As Integer
Return Me.GetHashCode()
End Function
#End Region
End Structure
<Flags()> _
Public Enum RoundedCorner
TopLeft = 2
TopRight = 4
BottomLeft = 8
BottomRight = 16
All = TopLeft Or TopRight Or BottomLeft Or BottomRight
End Enum
End Class
Conclusion
(J'ai trouvé util de le traduire pour l'intégrer à mes applications)
''''Exemple d'utilisation Private Sub form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint sbDesign(e) End Sub
Private Sub sbDesign(ByVal e As System.Windows.Forms.PaintEventArgs) Dim rect As New Rectangle(0, 0, Me.Width, Me.Height) Dim gc As Graphics = Me.CreateGraphics() gc.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality Dim rr As clsRoundedCorner.RoundedRectangle = _ New clsRoundedCorner.RoundedRectangle(0, 0, Width, Height, RoundedCorner.All, 16) rr.RoundedCorners = RoundedCorner.All gc.FillPath(New Drawing2D.LinearGradientBrush(rr.ToRectangle(), _ Color.Honeydew, Color.LightGreen, _ Drawing2D.LinearGradientMode.ForwardDiagonal), rr.ToGraphicsPath()) End Sub
Sources du même auteur
Sources de la même categorie
Commentaires et avis
Discussions en rapport avec ce code source dans le forum
Largeur du trait d'un rectangle arrondi [ par pledoux ]
Bonjour,J'utilise le fonction RoundRect de l'API pour imprimer un rectangle avec les coins arrondis. Mais je ne trouve pas la propriété qui
Imprimer un rectangle arrondi [ par sreef ]
Salut je cherche comment faire pour imprimer un rectangle avec des angles arrondis contenu dans un picture box.Sreef
Impression Rectangle arrondi avec API [ par sreef ]
J'ai créé un rectangle arrondi avec les API (RoundRect) mais je n'arrive pas à l'imprimer, j'ai essayé de différentes manières mais je n'y arrive pas,
dessiner un rectangle à coins arrondis en visual asic [ par nihadelg ]
j aimerai avoir une representation graphique des elments en VB et comment dessiner des boutons sous forme des rectangles à coins arrondis ainsi que d
rounded + GradientFill [ par peug ]
Hello,J'ai une fonction qui dessine un rectangle arrondi dans le genre :lr=RoundRect(hdc, X1, Y1, X1 + lWidth, Y1 + lheight, 5, 5)Mais j'aimeria qu'il
Problème power point (pr JP Forestier) [ par chtoune ]
Bonjour, Suite au message ci-dessous, j'ai trouvé la solution à mon problème cependant, il y a un pet
ajouter un graphics dans un graphics [ par dragon ]
Bonjour à tous, j'ai un petit problèmeje suis en train de me créer un System.Drawing.Printing.PrintDocument qui gère parfaitement les sauts de page. B
exploiter l'espace d'un rectangle dans lequel on reproduit le maximum de fois des objets selectionnés [ par akram85ing ]
sur autocad 2004, je veux un code (vba ou lisp) avec lequel je peux faire ceci :* je selectionne un ensemble des objets.* connaitre, dans un recta
placer une forme géometrique plusieurs fois dans un rectangle [ par akram85ing ]
bonjouron a :un rectangle de longueur L et de largeur l une forme géométrique quelconquequel est le nombre maximal de cette forme que peut c
Faire varier la grandeur d'un rectangle vers le haut. (vb6) [ par gaudreaua ]
Bonjour,J'ai un petit problème de programmation que je porte à votre attention... à qui la chance de m'aider Je vous explique...je veux créer un recta
|
Derniers Blogs
UNE JOLIE-HORLOGE ET PAS QU'UN PEU !UNE JOLIE-HORLOGE ET PAS QU'UN PEU ! par neodante
Pour les possesseurs d'iPhone, ça y est Bijin Tokei - qui se traduit littéralement en Français par " Jolie Horloge " - est arrivé et GRATUITEMENT s'il vous plaît ! Après la version Tokyo, Hokkaido, night club, racing, Gal, "pour les mademoiselles'", . voi...
Cliquez pour lire la suite de l'article par neodante TECHDAYS PARIS 2010 : CONNECTEZ VOS DONNéES à SHAREPOINT 2010 AVEC LES BUSINESS CONNECTIVITY SERVICESTECHDAYS PARIS 2010 : CONNECTEZ VOS DONNéES à SHAREPOINT 2010 AVEC LES BUSINESS CONNECTIVITY SERVICES par ROMELARD Fabrice
Animé par: Gaetan Bouveret et Julien Chomarat Business Connectivity Services (BCS) est dans SharePoint 2010 la version 2 de Business Data Catalog (BDC dans SharePoint 2007). Il s'agit de la solution permettant de visualiser des données provenan...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice [DIVERS] SUIVRE VOS SéRIES PRéFéRéS SUR LA TOILE[DIVERS] SUIVRE VOS SéRIES PRéFéRéS SUR LA TOILE par orion
Comme de nombreux geek, je suis un grand amateur de série TV et je rate régulièrement des épisodes de mes séries préférés. Une solution s'offre à vous avec ce merveilleux site : Tv Gorge - www.tvgorge.com Moteur de recherche à l'appui, vous pouvez ...
Cliquez pour lire la suite de l'article par orion TECHDAYS PARIS 2010 : LA BI DANS SHAREPOINT 2010TECHDAYS PARIS 2010 : LA BI DANS SHAREPOINT 2010 par ROMELARD Fabrice
Animé par: Vincent Bellet et Baptiste Giraudier La BI dans SharePoint 2010, Les nouveaux services d'application dans SP2010 et SQL Server Reporting services 2008 R2. La BI dans SharePoint est généralisée pour tous afin de permettre à tous les coll...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice
Logiciels
DB-MAIN (9.1.0)DB-MAIN (9.1.0)DB-MAIN is a data-modeling and data-architecture tool. It is designed to help developers and anal... Cliquez pour télécharger DB-MAIN Xilisoft DPG Convertisseur (5.1.37.0120)XILISOFT DPG CONVERTISSEUR (5.1.37.0120)Xilisoft DPG Convertisseur offre aux fans de Nintendo DS une bonne solution leur permettant de dé... Cliquez pour télécharger Xilisoft DPG Convertisseur GraphicsGale (2.01.01)GRAPHICSGALE (2.01.01)GraphicsGale est un logiciel de PixelArt avec de nombreuse fonctionnalités permettant de réalisé ... Cliquez pour télécharger GraphicsGale Architecte 3D (Platinum 2010)ARCHITECTE 3D (PLATINUM 2010)Architecte 3D Platinium vous permet de concevoir facilement les plans votre future maison, de l'é... Cliquez pour télécharger Architecte 3D TeamViewer 5 (TeamViewer 5)TEAMVIEWER 5 (TEAMVIEWER 5)Dépanner un ami,expliquer une manipulation devient un jeu d'enfant.
Prise en main d'un autre ord... Cliquez pour télécharger TeamViewer 5
|