返回首页

我继承了标准的面板控制,创建一个自定义边框颜色的面板。问题是,同时面板上的形式和任何其他形式的跨移动,它描绘hapazard线的面板整个面板的背景,自定义边框颜色相同的颜色。我试图刷新面板或废止其Paint事件,但无济于事。同样是发生在设计编辑器的设计。这究竟是为什么,以及如何摆脱它?
我的代码如下:


Namespace CustomPanelControl

    Public Class CustomPanel

        Inherits Panel

 

        Public Sub New()

            MyBase.New()

        End Sub

 

        Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)

            MyBase.OnPaint(e)

 

            'Set the backcolor of the panel according to the focus on it.

            If Me.ContainsFocus Then

                Me.BackColor = Color.Yellow

            Else

                Me.BackColor = Color.White

            End If

 

            'Draw the border of the panel.

            If Me.BorderStyle = BorderStyle.None Then

                Dim borderWidth As Integer = 1

                Dim BorderColor As Color = Color.Blue

                ControlPaint.DrawBorder(e.Graphics, e.ClipRectangle, BorderColor, borderWidth, ButtonBorderStyle.Solid, BorderColor, borderWidth, ButtonBorderStyle.Solid, BorderColor, _

                borderWidth, ButtonBorderStyle.Solid, BorderColor, borderWidth, ButtonBorderStyle.Solid)

            End If

        End Sub

    End Class

End Namespace

回答

评论会员: 时间:2
|