0

我想在 Krypton Toolkit Panel 控件的中间画一条线,但没有画出这条线。

我在这里尝试了两种方法:在面板上画线没有出现

和这个:

Public Class Form1

Private Sub KryptonPanel1_Paint(sender As Object, e As PaintEventArgs) _
Handles KryptonPanel1.Paint

    Using p As New Pen(Brushes.YellowGreen)
        e.Graphics.DrawLine(p, sender.Width \ 2, 0, sender.Width \ 2, sender.Bottom)
    End Using

End Sub

End Class
4

1 回答 1

1

At this point, I think it's safe to conclude that the Krypton Toolkit Panel do not have the control style UserPaint.

"If true, the control paints itself rather than the operating system doing so. If false, the Paint event is not raised. This style only applies to classes derived from Control." - MSDN

If possible, you can try one of the following options.

Start by creating a custom control derived from Krypton Toolkit Panel.

Option 1

Append the flag in the constructor. (This will probably break the custom drawings in base class)

Public Sub New()
    MyBase.SetStyle(ControlStyles.UserPaint, True)
End Sub

Option 2

Override WndProc.

Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
    Try
        If ((m.Msg = WM_PAINT) OrElse (m.Msg = WM_ERASEBKGND)) Then
            Using g As Graphics = Me.CreateGraphics()
                Me.OnPaint(New PaintEventArgs(g, Me.ClientRectangle))
            End Using
        End If
    Catch ex As Exception
    Finally
        MyBase.WndProc(m)
    End Try
End Sub

Const WM_PAINT As Integer = 15
Const WM_ERASEBKGND As Integer = 20
于 2014-01-10T19:28:03.077 回答