本文介绍了绘画自定义面板控件(.Net Framework 4.0)中的问题.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我继承了标准面板控件,以创建具有自定义边框颜色的面板.问题是,当面板位于窗体上并且在任何其他窗体上移动时,它会在面板的整个背景上绘制与面板自定义边框颜色相同颜色的随意行.我尝试在其绘画事件中刷新或使面板无效,但无济于事.在设计编辑器中进行设计时,也会发生同样的情况.为什么会发生这种情况以及如何消除呢?
我的代码如下:

I have inherited the standard panel control to create a panel having custom border color. The problem is, while the panel is on a form and any other form is moved across it, it paints hapazard lines of the same color as the panel custom border color, all throughout background of the panel. I tried to Refresh or Invalidate the panel in its paint event but of no avail. The same is happening while designing in the design editor too. Why is this happening and how to get rid of it?
My code follows:

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

推荐答案


这篇关于绘画自定义面板控件(.Net Framework 4.0)中的问题.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-27 15:32
查看更多