2 pièce(s) jointe(s)
bug sur un usercontrol CustomGroupBox
bonjour,
En m'inspirant d'un code trouvé sur un forum, j'ai construit un custumGroupBox hérité du contrôle GroupBox mais qui permet de personnaliser la couleur de la bordure, son style et son épaisseur.
Dans un form, j'ai donc mis un tel contrôle et je lui ai associé un Tooltip
En mode exécution, le tooltip s'affiche quelques secondes sur le contrôle comme il se doit, mais en s'effaçant, il laisse une rémanence d'un new CustomGroupBox de la taille du tooltip.
Voir copies d'écran avant/après en PJ.
Je vous joins le code de ma classe. Quelqu'un a-t-il une idée d'où ce bug vient et comment le corriger ?
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
| Imports System.ComponentModel
Imports System.Windows.Forms
Imports System.Drawing
Public Class CustomGroupBox
Inherits GroupBox
Private _borderColor As Color
Private _borderStyle As ButtonBorderStyle
Private _borderWidth As Integer
Public Sub New()
MyBase.New()
Me._borderColor = Color.Black
Me._borderStyle = ButtonBorderStyle.Solid
Me._borderWidth = 1
End Sub
<Category("Appearance"), _
Description("Change la couleur de la bordure")> _
Public Property BorderColor() As Color
Get
Return Me._borderColor
End Get
Set(ByVal value As Color)
Me._borderColor = value
Me.Update()
End Set
End Property
<Category("Appearance"), _
Description("Change le style de la bordure")> _
Public Property BorderStyle() As ButtonBorderStyle
Get
Return Me._borderStyle
End Get
Set(ByVal value As ButtonBorderStyle)
Me._borderStyle = value
End Set
End Property
<Category("Appearance"), _
Description("Changer l'épaisseur de la bordure")> _
Public Property BorderWidth() As Integer
Get
Return Me._borderWidth
End Get
Set(ByVal value As Integer)
Me._borderWidth = value
End Set
End Property
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
Dim tSize As Size = TextRenderer.MeasureText(Me.Text, Me.Font)
Dim borderRect As Rectangle = e.ClipRectangle
borderRect.Y = (borderRect.Y + (tSize.Height \ 2))
borderRect.Height = (borderRect.Height - (tSize.Height \ 2))
ControlPaint.DrawBorder(e.Graphics, borderRect, Me._borderColor, Me._borderWidth, Me._borderStyle, Me._borderColor, Me._borderWidth, Me._borderStyle, Me._borderColor, Me._borderWidth, Me._borderStyle, Me._borderColor, Me._borderWidth, Me._borderStyle)
Dim textRect As Rectangle = e.ClipRectangle
textRect.X = (textRect.X + 6)
textRect.Width = tSize.Width + 6
textRect.Height = tSize.Height
e.Graphics.FillRectangle(New SolidBrush(Me.BackColor), textRect)
e.Graphics.DrawString(Me.Text, Me.Font, New SolidBrush(Me.ForeColor), textRect)
End Sub
End Class |