A.P.Gumby
Dec 13th, 2006, 05:40 AM
I can find examples on how to override the form paint event but how would I go about overriding a panel paint event?
Any help appreciated.
jmcilhinney
Dec 13th, 2006, 05:45 PM
You don't override events. You handle events and you override methods. If you want to provide custom painting functionality for a particular Panel on a particular form then you can handle its Paint event, just like you would for the form itself:Public Class Form1
Private Sub Panel1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint
'Provide your own custom logic here, e.g. draw a diagonal line.
e.Graphics.DrawLine(Pens.Black, 0, 0, Me.Width, Me.Height)
End Sub
End ClassAlternatively, and especially if you want to provide this same functionality for more than one Panel on more than one form, then you should declare your own class, inherit the Panel class and override its OnPaint method. It is the OnPaint method that raises the Paint event, so you invoke the standard functionality first and then you provide your own custom logic, e.g.Public Class PanelEx
Inherits Panel
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
'Invoke the standard functionality of the Panel class, including raising the Paint event.
MyBase.OnPaint(e)
'Provide your own custom logic here, e.g. draw a diagonal line.
e.Graphics.DrawLine(Pens.Black, 0, 0, Me.Width, Me.Height)
End Sub
End ClassYou then add instances of your own PanelEx class to your forms instead of vanilla Panel objects.
A.P.Gumby
Dec 14th, 2006, 02:41 AM
Thanks for the reply and my apologies for the nomenclature error.
I am plotting a scrolling graph on a panel and I needed to override the Paint method in order to eliminate flicker.