如何改变GroupBox的边框线颜色?是否需要重写GroupBox?具体怎样实现?
------解决方案--------------------
自己写一个吧
- VB.NET code
Imports System.ComponentModel Public Class GroupBoxControl Inherits Panel Private lbl As Label Private mBorderColor As Color = Color.Blue <Browsable(True)> _ Public Overrides Property Text() As String Get Return lbl.Text End Get Set(ByVal value As String) lbl.Text = value Me.Invalidate() End Set End Property Public Property BorderColor() As Color Get Return mBorderColor End Get Set(ByVal value As Color) mBorderColor = value Me.Invalidate() End Set End Property Private Sub GroupBoxControl_ControlAdded(ByVal sender As Object, ByVal e As System.Windows.Forms.ControlEventArgs) Handles Me.ControlAdded If e.Control.Left < 5 Then e.Control.Left = 5 If e.Control.Top < 15 Then e.Control.Top = 15 If e.Control.Right > Me.Width - 10 Then e.Control.Left = Me.Width - 10 - e.Control.Width If e.Control.Bottom > Me.Height - 10 Then e.Control.Top = Me.Height - 10 - e.Control.Height End Sub Private Sub GroupBoxControl_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint e.Graphics.DrawRectangle(New Pen(mBorderColor), New Rectangle(2, 8, Me.Width - 5, Me.Height - 12)) End Sub Public Sub New() lbl = New Label lbl.AutoSize = True lbl.Text = "GroupBox" Me.Controls.Add(lbl) End Sub Private Sub GroupBoxControl_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize lbl.Location = New Point(10, 1) End Sub End Class
------解决方案--------------------
还不如把边框设为不显示
然后自己画4条线上去