Hello Steve
According to your description, you need change the color of Groupbox border
from Black to White. (In VB.net 2005 ). Please don't hesitate to correct me
if I misunderstand anything.
This is a common issue. Because there is no public borderColor propery for
Groupbox, we cannot modify it by default. However, capturing the onpaint
event is the right direction. You could create customer class which
inherited GroupBox and overid its OnPaint event to draw the border the way
you like.
Zhi-Xin Ye provide a good sample for this issue. I also copy the content
as following for your convenience.
http://forums.microsoft.com/MSDN/Sho...56465&SiteID=1
[Changing border color of GroupBox]
Public Class myGroupBox
Inherits GroupBox
Private _borderColor As Color
Public Sub New()
MyBase.New()
Me._borderColor = Color.Black
End Sub
Public Property BorderColor() As Color
Get
Return Me._borderColor
End Get
Set(ByVal value As Color)
Me._borderColor = 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,
ButtonBorderStyle.Solid)
Dim textRect As Rectangle = e.ClipRectangle
textRect.X = (textRect.X + 6)
textRect.Width = tSize.Width
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
1) Open the Solution Explorer, Add a new Class and name the class as
"myGroupBox"
2) Put the above code in this class, rebuild your project,
3) Then, you will see a "myGroupBox" control on your toolbox, it has a
"BorderColor" property on the Misc group in the property view.
Hope this helps. If you still have anything unclear, please feel free to
let me know. I'm glad to assist you.
Have a great day,
Wen Yuan
Microsoft Online Community Support
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.