专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > VB Dotnet

怎么改变GroupBox的边框线颜色

发布时间:2011-06-23 16:04:18 文章来源:www.iduyao.cn 采编人员:星星草
如何改变GroupBox的边框线颜色?
如何改变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条线上去
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: