Draw line on a Krypton Panel?

225 views Asked by At

I would like to draw a line on the middle of a Krypton Toolkit Panel control but the line is not drawn.

I've tried both soultions here: draw line on panel not showing up

And this:

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
1

There are 1 answers

0
Bjørn-Roger Kringsjå On BEST ANSWER

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